我按照github教程中的指示创建了密钥,在github上注册了它们,并尝试显式地使用ssh-agent -然而,每当我尝试进行拉或推操作时,git仍然会继续询问我的密码。

原因可能是什么?


当前回答

一旦你启动了SSH代理,使用:

eval $(ssh-agent)

做:

To add your private key to it: ssh-add This will ask you your passphrase just once, and then you should be allowed to push, provided that you uploaded the public key to Github. To add and save your key permanently on macOS: ssh-add -K This will persist it after you close and re-open it by storing it in user's keychain. If you see a warning about deprecated flags, try the new variant: ssh-add --apple-use-keychain To add and save your key permanently on Ubuntu (or equivalent): ssh-add ~/.ssh/id_rsa

其他回答

在mac上, 如果你的SSH密钥每次都需要密码,你想跳过它,那么你可以试试下面,它对我来说很好

Eval "$(ssh-agent -s)" ssh-add -K .ssh/id_rsa 添加这个默认的SSH配置对我有用

主机* AddKeysToAgent是的 UseKeychain是的 IdentityFile ~ / . ssh / id_rsa

一旦你启动了SSH代理,使用:

eval $(ssh-agent)

做:

To add your private key to it: ssh-add This will ask you your passphrase just once, and then you should be allowed to push, provided that you uploaded the public key to Github. To add and save your key permanently on macOS: ssh-add -K This will persist it after you close and re-open it by storing it in user's keychain. If you see a warning about deprecated flags, try the new variant: ssh-add --apple-use-keychain To add and save your key permanently on Ubuntu (or equivalent): ssh-add ~/.ssh/id_rsa

我也有类似的问题,但其他答案并没有解决我的问题。我想我应该继续发布这篇文章,以防有人像我一样有一个奇怪的设置。

结果发现我有多个密钥,而Git首先使用了错误的密钥。它会提示我输入密码,然后我输入它,然后Git会使用另一个可以工作的密钥(我不需要在这个密钥上输入密码)。

我刚刚删除了它用来提示我输入密码的密钥,现在它工作了!

如果你没有使用GitBash并且在Windows上-你需要使用这个命令启动你的ssh-agent

start-ssh-agent.cmd

如果您的ssh代理没有设置,您可以以管理员身份打开PowerShell并将其设置为手动模式

Get-Service -Name ssh-agent | Set-Service -StartupType Manual

我不知道是否有人需要不同的东西,但这对我帮助很大 https://stackoverflow.com/a/6445525/11891580

对我来说,每次重启,我都必须运行ssh-add——apple-use-keychain来加载凭据,所以我把这个命令添加到堆栈溢出的答案,现在它已经修复了