Skip to content

Instantly share code, notes, and snippets.

@vrivellino
Last active August 29, 2015 14:14
Show Gist options
  • Save vrivellino/c6643d9fbeb450c12187 to your computer and use it in GitHub Desktop.
Save vrivellino/c6643d9fbeb450c12187 to your computer and use it in GitHub Desktop.
Persistent ssh-agent on remove box
# setup ssh-agent
agent_env_file=~/.ssh/agent.env
agent_sock=~/.ssh/agent.sock
if [ -f $agent_env_file ] ; then
. $agent_env_file > /dev/null
if ! kill -0 $SSH_AGENT_PID > /dev/null 2>&1; then
echo "Stale agent file found. Spawning new agent ..."
eval `ssh-agent -t 4h -a $agent_sock | tee $agent_env_file`
ssh-add
fi
else
echo "Starting ssh-agent ..."
eval `ssh-agent -t 4h -a $agent_sock | tee $agent_env_file`
ssh-add
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment