Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pdcharles/eee876a1382acf09602f926fd93e6b95 to your computer and use it in GitHub Desktop.
Save pdcharles/eee876a1382acf09602f926fd93e6b95 to your computer and use it in GitHub Desktop.
Git SSH Setup for VS Code

Setup for password protected Git SSH keys for VS Code on Windows

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.

How to do it

  1. Go to the Windows services, search for OpenSSH Authentication Agent, start it and set it to automatically start in the future image

  2. Set the sshCommand for git to use Windows' OpenSSH

git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe
  1. Inside a normal terminal, not git bash, add the key to the SSH Agent:
ssh-add <PATH_TO_YOUR_KEY>
  1. It will ask for your password, enter it, and then you are all set! 🙌
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment