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.
7 Answers
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:
The man page is, as is typical for man pages, heavy on detail and light on examples.
The article http://rabexc.org/posts/using-ssh-agent is pretty good, and it covers some more advanced situations, especially agent forwarding.
The Stack Exchange question, "what's the purpose of ssh-agent?" is also good.
-
Mint XFCE 19.3: this worked for me until reboot. I created a new RSA key with Seahorse and this seems persistent– PhilCommented Jun 15, 2020 at 9:43
-
WHEN GENERATING AN SSH KEY, DO I NEED TO BE MINDFUL OF SAVING THE KEY FINGERPRINT AND RANDOMART SOMEWHERE, WHILE IT HAS ALREADY SAVED THE PUBLIC KEY IN THE SPECIFIED DIRECTORY? Commented Mar 13 at 7:34
-
1
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.
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.)
-
Can also call
ssh-add
in your powershell init scripts, eg:$HOME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
– EfrenCommented May 17, 2021 at 7:28 -
@darmual Doing the
ssh-add
afterwards in the vscode terminal did the job for me +1 Commented Oct 11, 2022 at 7:43 -
@Efren, does that also work if your ssh certificate is passphrased?– darmualCommented Nov 17, 2022 at 8:37
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
-
-
For me, the passphrase prompt appears every time the machine is restarted. To solve this problem, I choose to put the
ssh-add
command in.zshrc
file. Commented Aug 5 at 5:36
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.
-
WHEN GENERATING AN SSH KEY, DO I NEED TO BE MINDFUL OF SAVING THE KEY FINGERPRINT AND RANDOMART SOMEWHERE, WHILE IT HAS ALREADY SAVED THE PUBLIC KEY IN THE SPECIFIED DIRECTORY? Commented Mar 13 at 7:33
-
1@Jazz-Weisman I can't believe it has taken me this many months of head-scratching and searching to find out why I couldn't get VSCode to stop asking me for my SSH key password. Your solution here is great - simple, and also makes sense of why I was having the problem. Thank you! I wish I could send you some bounty... Commented Apr 13 at 0:07
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
-
Updated my answer with details (summary only, tried to keep it short) Commented Jan 9, 2020 at 23:22
Disable auto fetching with git.autofetch = false
in the settings