git突然开始每次都要求输入SSH密钥密码 [英] git suddenly started to ask for SSH key password every time
问题描述
因此,我将git和github与MFA一起使用,因此,为避免烦人的密码询问,一年多以来,我一直在使用 git@github.com:user/repo.git
URL样式
So, I use git and github with MFA, so, to avoid annoying password asking, for more than a year I am using the git@github.com:user/repo.git
URL style.
几天前,我运行了 brew更新
,现在,每次尝试与github服务器同步时,git都会要求我输入密钥密码.
A couple of days ago, I ran a brew update
, and now, every time try to sync with github servers, git asks me the key password.
我到目前为止所做的:
-
检查了我的配置,对我来说似乎还可以,但是在这里(相关部分):
Checked my configs, seems ok to me, but here it is (the relevant part):
[user]
name = Carlos Alexandro Becker
email = caarlos0@gmail.com
helper = osxkeychain
试图更新git和osxkeychain,当前版本为:
Tried to update git and osxkeychain, current versions are:
git 2.4.1
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
为github.com清洁了osxkeychain
Cleaned osxkeychain for github.com
我看到的一件奇怪的事情是:
The one weird thing that I saw is this:
$ ssh-add ~/.ssh/id_rsa.pub
Could not open a connection to your authentication agent.
$ ssh-agent sh -c 'ssh-add ~/.ssh/id_rsa.pub'
Enter passphrase for /Users/carlos/.ssh/id_rsa.pub:
所以,我的猜测是ssh-agent无法正常工作,但我不知道为什么也不知道如何解决它.
So, my guess is that somehow ssh-agent is not working properly, but I don't have any idea why nor how to fix it.
推荐答案
自从您提到 brew
以来,我假设您正在Mac上运行.这也发生在我身上,解决方案是确保我将密码短语添加到了钥匙串(在Mac上自动启动的Mac版本的 ssh-agent
包括钥匙串支持):
Since you mentioned, brew
, I assume you're running on a Mac. This has also happened to me and the solution was to ensure that I added the passphrase to the keychain (the Mac version of ssh-agent
, automatically launched on a Mac, includes keychain support):
$ ssh-add -K
并存储其他密钥的密码:
And to store the passphrase for a different key:
$ ssh-add -K /path/to/private/key/file
特别是在我的情况下(因为我为GitHub使用了单独的密钥):
Specifically in my case (since I use a separate key for GitHub):
$ ssh-add -K ~/.ssh/github_rsa
要自动将密钥加载到ssh-agent并将密码短语存储在钥匙串中,您需要修改〜/.ssh/config:
To automatically load keys into the ssh-agent and store passphrases in your keychain, you need to modify your ~/.ssh/config:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
我从这里获得了以下信息:
I obtained this information from here:
- http://www-uxsup.csx.cam.ac.uk/〜aia21/osx/leopard-ssh.html#Passphrase
- https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/
以上内容解决了ssh密钥的OP问题.如果您还想缓存HTTPS凭据,则以下内容对Mac用户也很有用.您可以通过使用凭据帮助器来做到这一点.要告诉git使用 osxkeychain
助手,请确保已将其添加到您的〜/.gitconfig
(或〜/.config/git/config
).
The above addresses the OP issue for ssh keys. The following is also useful for Mac users if you want to cache your HTTPS credentials as well. You can do this by using a credential helper. To tell git to use the osxkeychain
helper, ensure this is added to your ~/.gitconfig
(or ~/.config/git/config
).
[credential]
helper = osxkeychain
您可以从命令行设置以下条目,而不是直接编辑文件:
Instead of editing the file directly, you can set this entry from the command line:
$ git config --global credential.helper osxkeychain
有关更多详细信息,请参见以下链接(包括如何验证系统是否已安装 osxkeychain
帮助器):
See these links for more detail (including how to verify that your system has the osxkeychain
helper installed):
- https://help.github.com/articles/caching-your-github-password-in-git/
- https://git-scm.com/book/gr/v2/Git-Tools-Credential-Storage
这篇关于git突然开始每次都要求输入SSH密钥密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!