When working with password protected ssh keys for git in VS Code on Windows, VS Code by default does not ask for the password
and times out with a permissions denied message. Adding the key to the SSH agent also does not work, since it needs to be started manually.
Of course it can be started in the ~/.profile
or ~/.bashrc
, but that is not helpful for the VS Code issue.
To fix this we can tell git to use the OpenSSH service of Windows and add the key there, that SSH agent can be started automatically under services and will then also work with VS Code. I found this fix somewhere on the internet after some searching but lost the post about it again, thus decided to write it down myself to not struggle with it again.
Note: This short guide only assists in setup for the key to work nicely with VS Code on Windows. For a guide on how to setup a SSH Key in general see the Github Docs or Gitlab Docs, especially the generate and add to Github/Gitlab parts.
-
Go to the Windows services, search for
OpenSSH Authentication Agent
, start it and set it to automatically start in the future -
Set the
sshCommand
for git to use Windows' OpenSSH
git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe
- Inside a normal terminal, not git bash, add the key to the SSH Agent:
ssh-add <PATH_TO_YOUR_KEY>
- It will ask for your password, enter it, and then you are all set! 🙌