问题
I am running OpenSSH on Windows, using the built-in OpenSSH included since the Autumn/Fall Creators Update.
I am using ssh just fine in my PowerShell, but Visual Studio Remote Development (and I guess Git for Windows?) are not using my OpenSSH. Instead, they seem to be using the Git for Windows SSH client from MinGW. This means all my ssh-add
ed keys are not present in the VS or Git ssh-agent
.
How can I get Visual Studio (and maybe Git?) to use the builtin OpenSSH install so that I can use the same ssh-agent
between them all?
PowerShell
Here is what SSH looks like in PowerShell:
c:\Users\myusername
> Get-Command ssh
CommandType Name Version Source
----------- ---- ------- ------
Application ssh.exe 7.7.2.1 C:\WINDOWS\System32\OpenSSH\ssh.exe
c:\Users\myusername
> Get-Command ssh-agent
CommandType Name Version Source
----------- ---- ------- ------
Application ssh-agent.exe 7.7.2.1 C:\WINDOWS\System32\OpenSSH\ssh-agent.exe
C:\Users\myusername
> Get-Command ssh-add
CommandType Name Version Source
----------- ---- ------- ------
Application ssh-add.exe 7.7.2.1 C:\WINDOWS\System32\OpenSSH\ssh-add.exe
c:\Users\myusername
> ssh-add -l
2048 SHA256:HASH_HERE C:\Users\myusername\.ssh\id_rsa (RSA)
Git Bash
myusername@COMPUTERNAME MINGW64 ~
$ which ssh
/usr/bin/ssh
myusername@COMPUTERNAME MINGW64 ~
$ which ssh-agent
/usr/bin/ssh-agent
myusername@COMPUTERNAME MINGW64 ~
$ which ssh-add
/usr/bin/ssh-add
myusername@COMPUTERNAME MINGW64 ~
$ ssh-add -l
Could not open a connection to your authentication agent.
Visual Studio
I am using VS Code Remote Development. Every time I log in to my remote computer, I am prompted for my private key's password.
Without private key auth, I am prompted for my logon password (for the remote user).
回答1:
This is a known issue/regression with VS Code Remote Development.
The workaround is simple: change VS Code's SSH path.
- Open VS Code settings.
- Search for
remote.SSH.path
. - Change the setting to
C:\Windows\System32\OpenSSH\ssh.exe
(orC:\\Windows\\System32\\OpenSSH\\ssh.exe
if editing JSON).
VS Code will now use the OpenSSH ssh-agent
.
来源:https://stackoverflow.com/questions/60819352/how-can-i-use-windows-built-in-openssh-ssh-agent-in-vs-code-instead-of-git-bas