Search code examples
windowsgitsshcygwinssh-agent

Using cygwin ssh-agent is running but git is still prompting for passphrase


I'm using cygwin as my terminal on Windows 7. I have found several suggestions to run ssh-agent in cygwin so I don't have to enter my password every time I run a git fetch/pull/push. I added the following to my .bash_profile and restarted my cygwin session:

SSH_ENV="$HOME/.ssh/environment"

function start_agent {
    echo "Initialising new SSH agent..."
    /usr/bin/ssh-agent -s | sed 's/^echo/#echo/' > "${SSH_ENV}"
    echo succeeded
    chmod 600 "${SSH_ENV}"
    . "${SSH_ENV}" > /dev/null
    /usr/bin/ssh-add;
}

# Source SSH settings, if applicable

if [ -f "${SSH_ENV}" ]; then
    . "${SSH_ENV}" > /dev/null
    #ps ${SSH_AGENT_PID} doesn't work under cywgin
    ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
        start_agent;
    }
else
    start_agent;
fi

It looks as if the ssh-agent and ssh-add are run successfully, but I am still prompted for my password.

Initialising new SSH agent...
succeeded
Enter passphrase for /cygdrive/c/Users/<username>/.ssh/id_rsa:
Identity added: /cygdrive/c/Users/<username>/.ssh/id_rsa (/cygdrive/c/Users/<username>/.ssh/id_rsa)

$ ssh-add -l
2048 <fingerprint> /cygdrive/c/Users/<username>/.ssh/id_rsa (RSA)

$ git fetch --all
Fetching origin
Enter passphrase for key '/c/Users/<username>/.ssh/id_rsa':

I am in fact using SSH and not HTTPS for my git connection (redacted private info):

$ git remote -v
origin  ssh://git@XXX/XXX.git (fetch)
origin  ssh://git@XXX/XXX.git (push)

The closest problem I've found for this issue is the following question:

ssh-agent doesn't work / save me from typing passphrase for git

However, I didn't rename my ssh under /git/bin.

Any suggestions on how to diagnose this issue? Thanks!


Solution

  • Here is an easier solution to this than the one above:

    1. Launch Services (can be found by typing Services in the search box on the Taskbar)
    2. Edit the settings of the "OpenSSH Authentication Agent"
    3. Set the Startup type to Automatic and Start the Service
    4. Launch the Edit the System Environment Variables (type Environment in the search box on the Taskbar)
    5. Add GIT_SSH variable with the value set to "C:\Windows\System32\OpenSSH\ssh.exe"

    Now when an SSH key is added, you will not need to continue to type the passphrase in a Windows command prompt or in a Cygwin Bash shell.