VSCode Keep asking for passphrase of SSH key

半腔热情 提交于 2021-01-26 08:50:46

问题


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.


回答1:


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.




回答2:


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.




回答3:


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.)




回答4:


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




回答5:


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' git@github.com

    'C:\Program Files (x86)\PuTTY\plink.exe' git@bitbucket.org

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



来源:https://stackoverflow.com/questions/42707896/vscode-keep-asking-for-passphrase-of-ssh-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!