Windows, VS Code, Git and SSH Authentication with passphrases

Have you spent the past several hours frantically searching the web for a solution of integrating Git with VSCode? Are you tempted to remove passphrases from your SSH Key just to get around Permission denied (publickey) errors every time you try and clone a repo?

Yes, it is disappointing that there is no clear documentation for this.
Hopefully, this will fill the gap.

Pre-requisites

Windows 10
Git installed
VSCode installed
Created an SSH key using the Git terminal and is passphrase protected.
Added your SSH public key to your chosen Git Service.

Solution

Before starting VSCode, open up a new Windows CMD window.
Enter the command: start-ssh-agent and you will be prompted to provide the passphrase to your SSH Key.

cmd start-ssh-agent
start-ssh-agent

Now you will be able to open VSCode and clone into your repository.

Automation

If you wanted to automate start-ssh-agent and open VSCode at the same time, I have built a batch script that will do just this.

Open text editor and paste in the code below. Save file as VSCode_ssh-agent.bat

I decided to place this file in my Windows home directory. On the Desktop, I created a shortcut to the .bat file and set the icon to point to:

C:\Users\[USER]\AppData\Local\Programs\Microsoft VS Code\Code.exe

The final result:

  1. Check if SSH-AGENT is running.
    If not, start SSH-AGENT and ask for the passphrase for your key.
  2. Start VSCode

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.