Git asking for SSH passphrase every time, while SSH gets it from agent
Asked Answered
S

1

6

I am on a Windows 10 Pro machine trying to do a git pull without having to enter my SSH passphrase every time. The key pair was generated, with a passphrase, and the public key was successfully added to my GitLab account.

In the 'Services' GUI I can see that 'OpenSSH Authentication Agent' is running, and in PowerShell if I do Get-Service ssh-agent I see the following, confirming the same information:

Status   Name               DisplayName
------   ----               -----------
Running  ssh-agent          OpenSSH Authentication Agent

When I do ssh -T [email protected] I get the "Welcome to Gitlab" message indicating a successful ssh connection, without passphrase entry.

I have the ssh agent running and the identity added (by running svn add, entering my passphrase, and getting a success message). Running "ssh -T [email protected]" in the same terminal succeeds without requiring the passphrase.

In the terminal I can run git commands (such as git push or git pull) and I am prompted for my passphrase, every time, and the operation succeeds.

In Visual Studio Code, when I click the GUI button to synchronize with origin, I get the error [email protected]: Permission denied (publickey,keyboard-interactive). enter image description here
This is likely because it's not prompting for a passphrase and one is required. When I click 'Open Git Log' or 'Show Command Output' I can see the command that was attempted. Running the exact same command in the Terminal within VSCode, or in another terminal type application, I am prompted for the passphrase and after I enter a correct passphrase, the operation succeeds.

The git remote origin url is the SSH URL in the format described here; it is not an HTTPS URL. The second-most-upvoted answer and another one further below on the same question suggest that once able to do an ssh command without passphrase, the git commands also work without a passphrase, and that is NOT what I'm observing here.

My ~./ssh/config file entries are:

User git
Hostname gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab_id_ed25519
AddKeysToAgent yes

How do I get git to use the passphrase stored in the ssh-agent instead of prompting every time?

Smaze answered 7/1, 2022 at 19:39 Comment(2)
Does this answer your question? Git for Windows - Asking for SSH passphrase every pushGentilis
While the link is useful, it does not, for the reasons noted in the answer below.Smaze
S
5

First, follow these instructions (also noted here) to set the GIT_SSH environment variable to C:\Windows\System32\OpenSSH\ssh.exe, which is the core of the solution.

However, that's not enough to solve the problem as observed. You have to restart Visual Studio to reload the environment variables, but even that still isn't enough because the Powershell instance still doesn't have $ENV:GIT_SSH. On the right side of the bar with headings like 'PROBLEMS', 'OUTPUT', 'TERMINAL' (selected), and 'DEBUG CONSOLE', click the down arrow next to the plus sign and select Powershell, which opens a new Powershell window with the same name but different icon: enter image description here or just click the plus sign and it'll be the same icon too. Either way, in this new terminal, you can type $ENV:GIT_SSH and read the value you just set. You can type exit in the old one to avoid using that by accident.

In the new console, you should be able to git push and git pull etc. without a passphrase, and the GUI option to synchronize will work without error too.

Smaze answered 7/1, 2022 at 19:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.