Skip to content

Instantly share code, notes, and snippets.

@wyrmiyu
Created June 28, 2018 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wyrmiyu/636268b4d3c695a561969d18bd1cb9f8 to your computer and use it in GitHub Desktop.
Save wyrmiyu/636268b4d3c695a561969d18bd1cb9f8 to your computer and use it in GitHub Desktop.
SSH_AGENT_PID=999999999999999
if [ -r ~/.ssh/agent ]; then
source ~/.ssh/agent >/dev/null
fi
if [ -r "/proc/$SSH_AGENT_PID/exename" ]; then
if [[ $(basename $(cat /proc/$SSH_AGENT_PID/exename)) != ssh-agent ]]; then
rm -f ~/.ssh/agent $SSH_AUTH_SOCK
unset $SSH_AGENT_PID
fi
else
if [ -n ${SSH_AUTH_SOCK+x} ]; then
unset SSH_AUTH_SOCK
SSH_AGENT_PID=9999999999999
fi
fi
if [ -z ${SSH_AUTH_SOCK+x} ] || [ ! -S "$SSH_AUTH_SOCK" ]; then
rm -f ~/.ssh/agent $SSH_AUTH_SOCK
[ -z ${SSG_AUTH_SOCK+x} ] || unset SSH_AUTH_SOCK
if [ -r "/proc/$SSH_AGENT_PID/exename" ]; then
if [[ $(basename $(cat /proc/$SSH_AGENT_PID/exename)) == ssh-agent ]]; then
kill $SSH_AGENT_PID
fi
unset SSH_AGENT_PID
fi
ssh-agent > ~/.ssh/agent
source ~/.ssh/agent
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment