10 days ago, Git suddenly stopped working on my Windows 10. Every time I ran a Git command to work with remote repository, e.g. git pull origin master, Git failed saying Permision denied (publickey)..

Cascading Selector

At first, I thought something must be going wrong with my SSH key. So I followed instructions from Set up an SSH key, re-generated a new key and added the public key to my Bitbucket account. It didn’t work. I tried several times but it wouldn’t help.

Later, someone from my team said he has met the same problems weeks ago. In the end, he has to switch to HTTPS. To reset the origin for the local repository to HTTPs:

git remote set-url origin https://stash.XXX.git

Bitbucket has a document Permanently authenticating with Git repositories explaining how to authenticate with credential helper. I didn’t try it personally, because I still wanted to figure out why SSH key authentication suddenly failed on my machine.

Finally, another colleague unfolded the mystery. There are two sets of SSH clients/agents on Windows 10. One is native to Windows, and the other is shipped with Git Bash.

Cascading Selector

When I ran ssh-add ~/.ssh/{private_key_file} in Git Bash to add the key to the ssh-agent, I only added the key to the SSH agent shipped with Git Bash. For some reason, it’s not enough.

Eventually, I found a blog Using the OpenSSH client included in Windows 10 (1809) as your Git’s SSH client explaining how to configure Git to use OpenSSH for Windows.

Briefly speaking, firstly, use the git config to specify the OpenSSH client.

git config --global core.sshcommand "C:/Windows/System32/OpenSSH/ssh.exe"

Next, find “OpenSSH Authentication Agent” in Windows service and change its Startup type to Manual.

Cascading Selector

Done. Now, when I set the origin of my Git repository back to SSH connection, it’s working again!