Skip to content

Instantly share code, notes, and snippets.

@daniel-perry
Created August 3, 2012 21:58
Show Gist options
  • Save daniel-perry/3251940 to your computer and use it in GitHub Desktop.
Save daniel-perry/3251940 to your computer and use it in GitHub Desktop.
how to setup ssh-agent so there is only one process running.
# ssh-agent singleton setup
# If no SSH agent is already running, start one now. Re-use sockets so we never
# have to start more than one session.
export SSH_AUTH_SOCK=$HOME/.ssh-socket
NKEYS_SSHAGENT=`ssh-add -l 2> /dev/null | wc -l`
if [ $NKEYS_SSHAGENT = 0 ]; then
# No ssh-agent running
rm -f $SSH_AUTH_SOCK
ssh-agent -a $SSH_AUTH_SOCK >/tmp/.ssh-script
source /tmp/.ssh-script
echo $SSH_AGENT_PID > $HOME/.ssh-agent-pid
rm -f /tmp/.ssh-script
ssh-add $HOME/.ssh/id_rsa
fi
# most of this is from here: http://www.electricmonk.nl/log/2012/04/24/re-use-existing-ssh-agent-cygwin-et-al/
# with some modifications to make it work in my environment and to add my key automagically..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment