Created
August 12, 2015 19:22
-
-
Save jbreams/6f50a11882b9cdddb812 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Add this to your .bashrc to automatically detect running ssh-agents and connect to them. | |
if [ "x$SSH_AGENT_PID" = "x" ]; then | |
# Set the ssh-agent PID to the oldest ssh-agent owned by the current user | |
export SSH_AGENT_PID=$(pgrep -U $USER -o ssh-agent) | |
if [ "x$SSH_AGENT_PID" = "x" ]; then | |
eval $(ssh-agent) | |
else | |
# Find the auth socket for this PID in /tmp | |
export SSH_AUTH_SOCK=$(find /tmp/ssh-* -type s -name agent.$((SSH_AGENT_PID - 1)) -print -quit 2>/dev/null) | |
fi | |
if [ "x$SSH_AUTH_SOCK" = "x" ]; then | |
echo "Error setting up ssh-agent. You're gonna have to type a lotta passwords!" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment