I’m just kicking the tires with Visual Studio Code. So far, it seems like a nice little editor! One thing that tripped me up a bit was the Git integration… permission denied errors due to git ssh keys that use passphrases.
Here’s how I solved it…
For some of my hosted repo’s, I use an SSH key instead of a username/password. That key has a passphrase on it.
Git Error: Permission Denied
When I opened that codebase in VS Code, the Git screens complained that it could not connect. The output from VS Code showed:
git fetch Permission denied, please try again. Permission denied, please try again. Permission denied (publickey,gssapi-with-mic,password). fatal: Could not read from remote repository.
Step 1: SSH-AGENT
My first step was to make sure that, from a windows command prompt, I could execute “git fetch” without any authorization prompts. SSH-AGENT is supposed to make this happen.
This works fine in the bash window, but is more troublesome from a standard command prompt. A bit of digging lead me to the “start-ssh-agent.cmd” batch file that’s installed with Git. That launches the ssh-agent and prompts me for the passphrases to the keys in my .ssh folder.
I enter the passphrase once and then git stops prompting me. Beautiful.
VS Code still threw permission denied errors at me. Investigating the SSH-AGENT situation a bit, it looks like the agent uses some environment variables. Those are set on the current command prompt, but VS code was launched with a separate environment. So VS Code didn’t seem to pick up or use the SSH-AGENT.
Step 2: Launch VS Code from Command Line
My solution was to follow this flow:
- Open a command prompt.
- Run “start-ssh-agent” and answer passphrase prompts.
- Run “code” to launch VS Code from that environment.
I’d love to hear if there is a better, cleaner, simpler way to make this work. Drop comment if you have a thought.
(Photo by https://www.flickr.com/photos/bill_harrison/)