我如何在 VS Code 中使用 Windows' 内置的 OpenSSH ssh-agent,而不是 Git bash's?

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

我在 Windows 上 运行 OpenSSH,使用 built-in OpenSSH included since the Autumn/Fall Creators Update.

我在我的 PowerShell 中使用 ssh 很好,但是 Visual Studio 远程开发(我猜 Git 用于 Windows?)没有使用我的 OpenSSH。相反,他们似乎正在使用来自 MinGW 的 Git for Windows SSH 客户端。这意味着我所有的 ssh-added 键都不存在于 VS 或 Git ssh-agent.

如何让 Visual Studio(也许 Git?)使用内置的 OpenSSH 安装,以便我可以在它们之间使用相同的 ssh-agent ?

PowerShell

下面是 SSH 在 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

我正在使用 VS Code Remote Development。每次登录远程计算机时,系统都会提示我输入私钥密码。

没有私钥验证,系统提示我输入登录密码(对于远程用户)。

这是 known issue/regression 使用 VS 代码远程开发。

解决方法很简单:更改 VS Code 的 SSH 路径。

  1. 打开 VS 代码设置。
  2. 搜索 remote.SSH.path
  3. 将设置更改为 C:\Windows\System32\OpenSSH\ssh.exe(如果编辑 JSON,则为 C:\Windows\System32\OpenSSH\ssh.exe)。

VS Code 现在将使用 OpenSSH ssh-agent