Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 505
citelao Avatar asked Mar 23 '20 18:03

citelao


People also ask

Can I use SSH Git authentication with VS Code?

VS Code works most easily with SSH keys without a passphrase. To use SSH Git authentication with VS Code, you have launch VS Code from a Git Bash prompt to inherit its SSH environment.

Does Git for Windows include OpenSSH?

Using the OpenSSH client included in Windows 10 (1809) as your Git's SSH client. Microsoft has included an OpenSSH client with Windows 10 since the Fall Creators Release (1709). This client has been installed by default since the April 2018 Update (1803).


1 Answers

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.

like image 63
citelao Avatar answered Oct 23 '22 11:10

citelao