14

I am trying to configure VSCode on my machine (Win10) to SSH to my remote servers using keys already loaded in Pageant running on the machine.

One way I found is to use "wsl-ssh-pageant", however I couldn't figure how to install on my machine even though I have WSL (Ubuntu)enabled on my machine.

Can someone help in configuring VSCode with pageant? Explain how to install "wsl-ssh-pageant".

Thanks

vikramaditya234
  • 1,278
  • 2
  • 18
  • 37
  • 1
    This github issue explains it all. I do it using the info explained in post #2 and #4 https://github.com/microsoft/vscode-remote-release/issues/61 – fred Dec 12 '20 at 21:06

2 Answers2

12

If Pageant has already loaded keys, then you can make a use of it by another application through the Plink (PuTTY Link) command-line interface.

If you want to work with e.g. a Git repository on remote server with credentials (keys), I have found a working solution: https://www.cgranade.com/blog/2016/06/06/ssh-keys-in-vscode.html (with already loaded keys to Pageant, the only missing part is last step 4).

You need to set a new environment variable in your Win10. For me it worked when I added a "system variable" not a "user variable".

The name of the variable is: "GIT_SSH"

The value is a full path to PuTTY\plink.exe, e.g: "C:\Program Files (x86)\PuTTY\plink.exe"

If you have VS Code opened already, close it and reopen again to make sure it sees the new environment variable.

Update (2021.11.10):

Now in my case, VSCode additionally needed what was described here in the solution: VS Code / Bitbucket / SSH - Permission denied (publickey)

7

Since Putty version 0.77, you don't need to use "wsl-ssh-pageant" nor PLINK anymore. It makes using pageant as ssh-agent for git in vscode much simpler.

<= Windows 10 : follow full instructions

>= Windows 11 : just ignore setting the environment variable GIT_SSH

Preconditions:

  1. Putty / Pageant >= Version 0.77 and start with new command pageant.exe --openssh-config %USERPROFILE%\.ssh\pageant.conf. It generates a file, that directs ssh to pageant, if it is included in .ssh\config. Please note: Resulting file is bound to running pageant.exe instance and changes with every time you start it!!! Easiest way is to include it in your autostart, where you can also add your private keys.
  2. Correct OpenSSH Pubkey is loaded in git. (Pubkey in Putty-format .ppk doesn't work!)
  3. Corresponding OpenSSH Private-Key is loaded in pageant.
  4. Create file "%USERPROFILE%\.ssh\config" and add following line include "pageant.conf". It will load the by pageant generated file for direction to pageant.
  5. Not in Win11!: For vscode, Environment variable GIT_SSH must direct to Windows ssh executable, which is usually in C:\Windows\System32\OpenSSH\ssh.exe. To set this permanently even on systems restricted by administrator: in Powershell execute
[Environment]::SetEnvironmentVariable("GIT_SSH", "$((Get-Command ssh).Source)", [System.EnvironmentVariableTarget]::User)

It will add a permanent user specific environment variable, that can be used by vscode (see in registry under Computer\HKEY_CURRENT_USER\Environment\GIT_SSH)

Now test git access from command line, to see if ssh access to your git-repo works properly.

Open a fresh cmd prompt. If following command works similar, all would be fine:

C:\Users\<myuser>> ssh -T git@<your-git-url-goes-here>
Welcome to GitLab, @<your username in git>!

If it works like this, you can start trying git in vscode. But don't forget to restart vscode.

D. Lohrsträter
  • 306
  • 3
  • 9