Created
August 28, 2011 17:06
-
-
Save Jessidhia/1176927 to your computer and use it in GitHub Desktop.
.profile snippet for making sure an ssh-agent is running
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
# Make sure we always have a running ssh-agent | |
# Try and reuse a running one if possible, otherwise start a new one | |
fail_agent_check () { | |
ssh-add -l >/dev/null 2>&1 | |
[ "$?" = 2 ]; | |
} | |
if [ -r "${HOME}/.ssh_agent" ]; then | |
# the .ssh_agent file already has an 'echo' so augment it | |
printf "Found SSH " | |
. "${HOME}/.ssh_agent" | |
if fail_agent_check; then | |
echo "... but it's dead" | |
unset SSH_AGENT_PID | |
fi | |
fi | |
if [ -z "$SSH_AGENT_PID" ] || fail_agent_check; then | |
rm -f "${HOME}/.ssh_agent" | |
ssh-agent -s | (umask 0377; cat >"${HOME}/.ssh_agent";) | |
printf "Started new SSH " | |
. "${HOME}/.ssh_agent" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment