Using pageant with VSCode on Windows 10

16.6k views Asked by At

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

3

There are 3 answers

2
Daniel 'Thready' Nitecki On

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)

0
D. Lohrsträter On

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 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 in properties, where you can optionally also add your private keys as parameter to the command in field Target. Example: "C:\Program Files\PuTTY\pageant.exe --openssh-config %USERPROFILE%\.ssh\pageant.conf" %USERPROFILE%\.ssh\myopensshkey. If you add your private key, each time at start you get a tiny pop-up window to type your passphrase.

  2. Corresponding OpenSSH Private-Key is loaded in pageant (see also step 1).

  3. Create or update file "%USERPROFILE%\.ssh\config" and add following line include "pageant.conf". It will load the by pageant generated file for direction to pageant.

  4. Correct OpenSSH Pubkey is loaded in git. (Pubkey in Putty-format .ppk doesn't work!)

  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.

0
Gunnar Arndt On

I used this thread as an entry point to solve the problem for me, although it is already a bit older.

It is possible to use the OpenSSH agent integrated in Windows 11 as described in this article - no need for PuTTY adaptation anymore.

It is important to install Git for Windows such that it does not use its included SSH implementation, but an external one (available in the PATH by Windows). I installed a newer version of Git to achieve this, and made the respective choice in the installer.

Note that this solution is not VS Code specific - you must 'only' get the interaction between git and ssh-agent to work, and VS Code will make use of it automatically.