The Problem
I recently updated my ssh keys for GitHub account on my Mac and after adding the public key in GitHub everything worked as expected from the command line. When I did a…
$ git pull
…I was asked for the passphrase of my private key and the pull was executed. Great.
$ git pull
Enter passphrase for key '/Users/christiandennig/.ssh/id\_rsa':
Already up to date.
But when I did the same from Visual Studio Code, I got the following error:
As you can see in the git logs, it says “Permission denied (publickey)”. This is odd, because VS Code is using the same git executable as the commandline (see the log output).
It seems that VS Code isn’t able to ask for the passphrase during the access to the git repo?!
ssh-agent FTW
The solution is simple. Just use ssh-agent on your machine to enter the passphrase for your ssh private key once…all subsequent calls that need your ssh key will use the saved passphrase.
Add your key to ssh-agent (storing the passphrase in MacOS Keychain!)
$ ssh-add -K ~/.ssh/id\_rsa
Enter passphrase for /Users/christiandennig/.ssh/id\_rsa:
Identity added: /Users/christiandennig/.ssh/id\_rsa (XXXX@microsoft.com)
The result in Keychain will look like that:
When you now open Visual Studio Code and start to synchronize your git repository the calls to GitHub will use the credentials saved via ssh-agent and all commands executed will be successful.
HTH.
(BTW: Happy New Year 🙂)
Top comments (0)