Created
May 27, 2013 12:03
-
-
Save mfdela/5656719 to your computer and use it in GitHub Desktop.
Launching ssh-agent on a remote host and reusing the same agent for all ssh connections.
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-launch-agent() { | |
echo "Starting ssh-agent for remote connection..." | |
eval `ssh-agent -s -a "$HOME/.ssh/ssh-auth-remote.sock"` | |
echo $SSH_AGENT_PID > "$HOME/.ssh/ssh-agent-remote.pid" | |
ssh-add | |
} | |
if [ ! -z "$SSH_TTY" ]; then | |
[ ! -f "$HOME/.ssh/ssh-agent-remote.pid" ] && ssh-launch-agent | |
pid=`cat "$HOME/.ssh/ssh-agent-remote.pid"` | |
if [ ! -d /proc/$pid ]; then | |
# restarting ssh-agent | |
ssh-launch-agent | |
else | |
# existing agent running | |
export SSH_AGENT_PID=$pid | |
export SSH_AUTH_SOCK="$HOME/.ssh/ssh-auth-remote.sock" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment