Skip to content

Instantly share code, notes, and snippets.

@aumgn
Last active December 17, 2015 15:39
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 aumgn/5633023 to your computer and use it in GitHub Desktop.
Save aumgn/5633023 to your computer and use it in GitHub Desktop.
ssh-agent for Windows Contrary to most scripts available on the web, this one allows to use the same ssh-agent for all shell sessions. It works by specifiying an explicit socket '/tmp/ssh-agent' and using 'ps' to retrieve the pid.
function init_ssh_agent {
echo "Initializing new SSH agent..."
rm -f /tmp/ssh-agent
eval `ssh-agent -a /tmp/ssh-agent`
}
function setup_existing_ssh_agent {
echo "Using existing SSH agent..."
export SSH_AUTH_SOCK=/tmp/ssh-agent
export SSH_AGENT_PID=$(ps -s -u $USERNAME | grep ssh-agent | cut -d' ' -f4)
}
if [[ -n $(ps -f -u $USERNAME | grep ssh-agent) ]]; then
setup_existing_ssh_agent
else
init_ssh_agent
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment