Last active
August 29, 2015 14:09
-
-
Save jamesgraves/9af46a544b6dc7da9097 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Snippit to put in your ~/.bash_profile. | |
# This will look for a running ssh-agent process on your machine, | |
# and connect to it if possible. Otherwise it will start up a | |
# new instance. | |
# If you ever wanted to put it in your .bashrc (not recommended) | |
# be sure to delete all print statements. | |
export SSH_ENV=$HOME/.ssh/environment_${HOSTNAME} | |
function start_agent { | |
echo -n "Initialising new SSH agent... " | |
touch ${SSH_ENV} | |
chmod 600 ${SSH_ENV} | |
/usr/bin/ssh-agent -s | sed 's/^echo/#echo/' > ${SSH_ENV} | |
echo "succeeded." | |
. ${SSH_ENV} > /dev/null | |
} | |
# Source SSH settings, if applicable | |
ssh-add -l > /dev/null 2>&1 | |
if [ $? -eq 0 -o $? -eq 1 ]; then | |
echo "SSH Agent found." | |
else | |
echo -n "Looking for SSH Agent... " | |
if [ -f "${SSH_ENV}" ]; then | |
. ${SSH_ENV} > /dev/null | |
ssh-add -l > /dev/null 2>&1 | |
if [ $? -eq 0 -o $? -eq 1 ]; then | |
echo "found pid: ${SSH_AGENT_PID}." | |
else | |
echo "not found." | |
start_agent; | |
fi | |
else | |
start_agent; | |
fi | |
ssh-add -l | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment