Remember git passphrase in WSL

允我心安 提交于 2019-12-02 06:03:42

问题


I run Windows 10 with WSL. I have the desired behaviour on one computer, but cannot replicate elsewhere. Here's what I'm after:

  1. First time I run a remote git command using my ssh key, git prompts me for the passphrase
  2. Subsequent times no prompt, including in new terminal windows (I use ConEmu)
  3. When all console windows are closed, back to #1

Things I've tried:

  • using eval $(ssh-agent), followed by ssh-add; it will remember the passphrase, but if I put it in my ~/.bash_profile then it prompts me for every new console window, and I open a lot - many of which I'm not using git in.
  • setting git config --global credential.helper to cache or store
  • everything here
  • using bash.exe and wsl.exe to get git-credentials-manager.exe to work

Here's an example of what I've put in my ~/.gitconfig: [credential] helper = "/mnt/c/Program\\ Files/Git/mingw64/libexec/git-core/git-credential-manager.exe"

I've installed the git credential manager from here and have also tried the main Git For Windows installation as an alternative.

How can I encourage it to remember my passphrase?


回答1:


I found the answer!

First, make sure you have ssh-agent running all the time by adding eval $(ssh-agent) to your .bash_profile.

Then add AddKeysToAgent yes to your ssh config:

touch ~/.ssh/config
chmod 600 ~/.ssh/config
echo "AddKeysToAgent yes" >> ~/.ssh/config

You'll get prompted when you first do some ssh, but the passphrase will be automatically added to the ssh-agent so you won't have to type it again until you end your session and start a new one.



来源:https://stackoverflow.com/questions/52423626/remember-git-passphrase-in-wsl

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