Jonathon
Jonathon

Reputation: 682

VSCode Keep asking for passphrase of SSH key

I have recently upgrade my VSCode version 1.10.2. As I put passphrase on my private SSH key, it started to ask for it frequently even when I entered it multiple times, which is very annoying. Is there anyway I can get rid of it? Thanks. enter image description here

Upvotes: 37

Views: 40690

Answers (7)

Jazz Weisman
Jazz Weisman

Reputation: 604

If you're using windows, try launching VS Code from a Git Bash that you've already unlocked the SSH key in, so that VSCode inherits the SSH environment.

Can I use SSH Git authentication with VS Code?

Yes, though VS Code works most easily with SSH keys without a passphrase. If you have an SSH key with a passphrase, you'll need to launch VS Code from a Git Bash prompt to inherit its SSH environment.

https://code.visualstudio.com/docs/sourcecontrol/faq#:~:text=Can%20I%20use%20SSH%20Git,to%20inherit%20its%20SSH%20environment.

Upvotes: 6

Anton Thomas
Anton Thomas

Reputation: 350

For any MacOS users encountering issues, Github has some great documentation on this issue.

Make sure to change the Host to whatever git provider you are using (e.g. github.com, bitbucket.org) and make the IdentityFile point to the file name of your private key (e.g. ~/.ssh/id_ed25519, ~/.ssh/id_rsa)

Host github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519

Make sure to replace the file path in the command for adding the SSH key to KeyChain as well

ssh-add --apple-use-keychain ~/.ssh/id_ed25519

Upvotes: 7

darmual
darmual

Reputation: 269

For Windows 10, if you have stumbled across this issue using the Remote - SSH plugin, run the following in powershell (as admin):

# Make sure you're running PowerShell as an Administrator
Set-Service ssh-agent -StartupType Automatic
Start-Service ssh-agent
Get-Service ssh-agent

(As suggested by the documentation that is pointed to by this comment on a git (non-)issue.)

Upvotes: 14

Rayee Roded
Rayee Roded

Reputation: 2630

There is a great guide on how to solve it in Windows here:

https://www.cgranade.com/blog/2016/06/06/ssh-keys-in-vscode.html

Summary:

  • Install Required Software (Putty)
  • Setup Private Keys (use ssh-keygen which will create private and public keys in .ssh folder)
  • Set up SSH Agent: have Pageant tool run on Windows startup
  • import your key to ppk format

Run PuTTYgen from the Start Menu and select File → Load Key.... From there, navigate to C:\Users\.ssh\ and select id_rsa (the private key). You may have to drop down the file types selector in the dialog box to see this, as PuTTYgen defaults to filtering out everything but files ending in *.ppk. Once selected, you’ll be prompted by PuTTY to unlock your key by typing in your passphrase. Do so, and PuTTYgen will show the corresponding public key. Select File → Save private key to export your private key in PuTTY, rather than OpenSSH, format. I suggest saving it as id_rsa.ppk in the same folder as id_rsa

  • run Pageant

Finally, run Pageant from the Start Menu (in the future, this will be handled automatically by the shortcut we created above). This will add a new icon to your system tray. It may be hidden by the arrow; if so, click the arrow to make all fo the system tray icons visible. Right-click on Pageant and select Add Key. Browse to where you saved id_rsa.ppk and select it. You’ll be prompted to unlock your key. Upon doing so, your unlocked key will then be made available in Pageant until you log out or quit Pageant.

  • Add fingerprints, in shell run one of those two (depending on your needs)

    'C:\Program Files (x86)\PuTTY\plink.exe' [email protected]

    'C:\Program Files (x86)\PuTTY\plink.exe' [email protected]

  • Configure GIT_SSH to be C:\Program Files (x86)\PuTTY\plink.exe

Upvotes: 1

Magas
Magas

Reputation: 514

Disable auto fetching with git.autofetch = false in the settings

Upvotes: -2

Scott McPeak
Scott McPeak

Reputation: 12739

Yes, you can avoid this prompt, without removing the passphrase.

To do so is usually fairly simple and relies on the ssh-agent program. First, before starting VSCode, at a bash shell prompt, run:

$ eval `ssh-agent`

This will start an ssh-agent process in the background that will remember the decrypted private key in its memory. The reason for eval is ssh-agent prints two environment variable settings that need to be added to the shell. (You can also just run it normally, then manually copy and paste its output back into the shell.)

Next, run:

$ ssh-add

This will prompt you for your passphrase, after which ssh-agent will provide private key services to any other process that needs it.

Finally, start VSCode from the same shell you ran the first command:

$ code

This way VSCode will inherit the environment variables it needs to get key services from ssh-agent, and therefore will not prompt for your passphrase so long as the ssh-agent process continues running.

Further References

Unfortunately, despite it being so useful, good (concise, readable) documentation on ssh-agent is hard to find. But here are some possibilities:

Upvotes: 49

The only solution I've found was remove the passphrase:

ssh-keygen -p

It will ask your current passphrase and leave blank the new passphrase to remove it.

Upvotes: 15

Related Questions