2014-06-07

How to use only one instance of ssh-agent per host, purr user.

This is a script to connect to a running ssh-agent from a user shell, add the user's default DSA identity
#!/bin/sh 
# The following command returns the PID of the currently 
#   running ssh-agent process; This value needs to get stored into
#   SSH_AGENT_PID
#
# ps -u $USER | grep ssh-agent | sed -e 's/^\s*//;' | cut -d' ' -f1
#
# The other value we want in order to be able to use an instance of 
# ssh-agent is the SSH_AUTH_SOCK value - this is a file system name 
# a socket maintained by the ssh-agent instance.  It will be in the
# ${TMP}/ directory space...
export SSH_AUTH_SOCK=`ls --color=none /tmp/ssh-*/agent.*`
export SSH_AGENT_PID=`ps -u $USER | grep ssh-agent | sed -e 's/^\s*//;' | cut -d' ' -f1`
echo SSH_AGENT_PID: $SSH_AGENT_PID
echo SSH_AUTH_SOCK: $SSH_AUTH_SOCK
echo "Adding default .ssh/id_dsa using ssh-add..."
ssh-add
echo kthxbai.