Home > Back-end >  Why does git asks for key passphrase when ssh does not?
Why does git asks for key passphrase when ssh does not?

Time:10-07

I've looked through several of Q&As about why git asks for an SSH key passphrase every time, but I haven't found one that describes my situation. What makes my situation different is that I have successfully created an ssh key, added it to the agent, and the agent is running. So when I run:

ssh -T [email protected]

I immediately get the success message "You've successfully authenticated, but GitHub does not provide shell access." It does not ask for a passphrase.

The perplexing thing is that in powershell when I navigate to a git repo associated with that account, and run a git command like this:

cd ~/mygitrepo
git fetch

I get asked to Enter passphrase for key 'C:\Users\me\.ssh\github'.

If I enter the passphrase, I successfully can fetch from the repo.

Why am I asked to enter the passphrase when running a git command but not when running an ssh command?

Extra details

I'm running Windows 10, using PowerShell inside Windows Terminal. I use ssh everyday to connect to various remotes and it never asks for a passphrase.

Snippet from ~/.ssh/config

Host github.com
    HostName github.com
    User git
    IdentityFile C:\Users\me\.ssh\github

Snippet from ~/mygitrepo/.git/config

[remote "origin"]
    url = [email protected]:myuser/myrepo.git

CodePudding user response:

When you run a git command, by default it uses its own version of ssh, which fails to communicate with the Windows ssh-agent.

Find out what binary Windows is using:

Powershell> where.exe ssh
CMD> where ssh

For me the result is C:\Windows\System32\OpenSSH. Now force git to use that binary by setting the following line in your global .gitconfig file:

[core]
    sshCommand = "C:/WINDOWS/System32/OpenSSH/ssh.exe"
...
  • Related