How can I use Windows' built-in OpenSSH ssh-agent in VS Code, instead of Git bash's?

六月ゝ 毕业季﹏ 提交于 2021-01-29 02:08:15

问题


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-added 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.

  1. Open VS Code settings.
  2. Search for remote.SSH.path.
  3. Change the setting to C:\Windows\System32\OpenSSH\ssh.exe (or C:\\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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!