Setting up ssh-agent for bash under windows

The bash shell for windows is a good extension to use git unter windows. But if you use ssh-based connections it is frustating to enter the passphrase for each connection.

Activating the ssh-agent solve this problem. Create the file .profile in your bash home directory and after starting the bash shell it also starts the ssh-agent and asks once for your ssh passphrase. The passphrase is cached in the ssh-agent during your bash session.

#!bash.exe
export SSH_AUTH_SOCK=/tmp/.ssh-socket
echo ;
echo Starting connection with ssh-agent...
ssh-add -l 2>&1 >/dev/null
if [ $? = 2 ]; then
  rm -f /tmp/.ssh-script /tmp/.ssh-agent-pid /tmp/.ssh-socket
  # Exit status 2 means couldn't connect to ssh-agent; start one now
  echo Creating new ssh-agent...
  ssh-agent -a $SSH_AUTH_SOCK > /tmp/.ssh-script
  . /tmp/.ssh-script
  echo $SSH_AGENT_PID > /tmp/.ssh-agent-pid
  ssh-add;
  echo ssh-agent set up successfully.
  ssh-add -l
fi

Leave a comment