我按照github教程中的指示创建了密钥,在github上注册了它们,并尝试显式地使用ssh-agent -然而,每当我尝试进行拉或推操作时,git仍然会继续询问我的密码。
原因可能是什么?
我按照github教程中的指示创建了密钥,在github上注册了它们,并尝试显式地使用ssh-agent -然而,每当我尝试进行拉或推操作时,git仍然会继续询问我的密码。
原因可能是什么?
当前回答
我也有类似的问题,但其他答案并没有解决我的问题。我想我应该继续发布这篇文章,以防有人像我一样有一个奇怪的设置。
结果发现我有多个密钥,而Git首先使用了错误的密钥。它会提示我输入密码,然后我输入它,然后Git会使用另一个可以工作的密钥(我不需要在这个密钥上输入密码)。
我刚刚删除了它用来提示我输入密码的密钥,现在它工作了!
其他回答
如果您已经尝试了ssh-add,并且仍然提示您输入密码,那么请尝试使用ssh-add -K。这将您的密码短语添加到您的钥匙串。
更新:如果你使用的是macOS Sierra,那么你可能需要再做一步,因为上面的步骤可能不再有效。在~/.ssh/config中添加以下命令:
Host *
UseKeychain yes
如果你用的是Win10:
我也有同样的问题。 (以前由于不同的问题,必须从这里用脚本单独更新ssh-agent)
Git确实访问了我的ssh配置(当我在ssh配置中有无意义的行时,Git会抛出异常),但似乎从不关心我通过ssh-agent添加并在配置中引用的私钥。
解决问题的方法是在PowerShell中执行以下命令:
git config core.sshCommand (get-command ssh).Source.Replace('\','/')
(详情见此连结)
我不知道是否有人需要不同的东西,但这对我帮助很大 https://stackoverflow.com/a/6445525/11891580
对我来说,每次重启,我都必须运行ssh-add——apple-use-keychain来加载凭据,所以我把这个命令添加到堆栈溢出的答案,现在它已经修复了
对于Windows或Linux用户,GitHub Docs中描述了一个可能的解决方案,为了方便起见,我在下面报告。
您可以在打开bash或Git shell时自动运行ssh-agent。复制以下行并将它们粘贴到~/。Profile或~/。bashrc文件:(
env=~/.ssh/agent.env
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
(umask 077; ssh-agent >| "$env")
. "$env" >| /dev/null ; }
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
agent_start
ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
ssh-add
fi
unset env
如果您的私钥没有存储在默认位置之一(如~/. SSH /id_rsa),您需要告诉SSH身份验证代理在哪里可以找到它。要将密钥添加到ssh-agent,输入ssh-add ~/path/ To /my_key。
现在,当您第一次运行Git Bash时,系统会提示您输入密码。ssh-agent进程将继续运行,直到您注销、关闭计算机或杀死该进程为止。
也许不是最安全的方法来解决这个问题,但不要设置密码短语,这是可选的。如果您不设置密码短语,它将不会请求它。你可以用更改密码
$ ssh-keygen -p -f ~/.ssh/id_ed25519
> Enter old passphrase: [Type old passphrase]
> Key has comment 'your_email@example.com'
> Enter new passphrase (empty for no passphrase): [Type new passphrase]
> Enter same passphrase again: [Repeat the new passphrase]
> Your identification has been saved with the new passphrase.