Created
January 16, 2013 20:16
-
-
Save benders/4550480 to your computer and use it in GitHub Desktop.
bashrc voodoo for consistently connecting to ssh-agent
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
# ssh-agent needs to be running and we need to export the SSH_AUTH_SOCK | |
# environment variable to point to its location in /tmp/ssh-something/agent.PID | |
# so, find the ssh-agent PID and derive the socket filename from it, and then | |
# find that file in its randomly-named directory in /tmp and export that for | |
# ssh to use. | |
set -x | |
SSH_AGENT_PID=`pgrep -n -u $USER ssh-agent` | |
if [ -n "$SSH_AGENT_PID" ]; then | |
guessed_ppid=`expr $SSH_AGENT_PID - 1` | |
export SSH_AGENT_PID | |
export SSH_AUTH_SOCK=`find /tmp -user $USER -name agent.$guessed_ppid -type s 2> /dev/null` | |
else | |
eval `ssh-agent` | |
fi | |
ssh-add | |
set +x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment