Skip to content

Instantly share code, notes, and snippets.

@silkentrance
Last active August 12, 2022 08:19
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 silkentrance/6dba5f7547c713f736416b54c5edbae0 to your computer and use it in GitHub Desktop.
Save silkentrance/6dba5f7547c713f736416b54c5edbae0 to your computer and use it in GitHub Desktop.
Git for Windows SSH Agent
SSH_AUTH_SOCK=~/.ssh/ssh-agent.sock
ssh_agent_pid=$(ps -aef | grep ssh-agent | tr -s ' ' | cut -f 3 -d ' ')
[ -e ${SSH_AUTH_SOCK} ] && [ -z ${ssh_agent_pid} ] && rm ${SSH_AUTH_SOCK}
ssh-add -l 2>/dev/null >/dev/null
[ $? -ne 0 ] && ssh-agent -a ${SSH_AUTH_SOCK} 2>/dev/null >/dev/null
export SSH_AUTH_SOCK
# add existing rsa keys
ssh-add ~/.ssh/*_rsa 2>/dev/null >/dev/null

This will prevent the ssh-agent from being started multiple times.

It will also add existing rsa keys to the ssh-agent.

Will also work on linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment