Skip to content

Instantly share code, notes, and snippets.

@Jessidhia
Created August 28, 2011 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jessidhia/1176927 to your computer and use it in GitHub Desktop.
Save Jessidhia/1176927 to your computer and use it in GitHub Desktop.
.profile snippet for making sure an ssh-agent is running
# 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