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

原因可能是什么?


当前回答

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

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

其他回答

如果你用的是Win10:

我也有同样的问题。 (以前由于不同的问题,必须从这里用脚本单独更新ssh-agent)

Git确实访问了我的ssh配置(当我在ssh配置中有无意义的行时,Git会抛出异常),但似乎从不关心我通过ssh-agent添加并在配置中引用的私钥。

解决问题的方法是在PowerShell中执行以下命令:

git config core.sshCommand (get-command ssh).Source.Replace('\','/')

(详情见此连结)

一旦你启动了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

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

start-ssh-agent.cmd

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

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

如果您已经尝试了ssh-add,并且仍然提示您输入密码,那么请尝试使用ssh-add -K。这将您的密码短语添加到您的钥匙串。

更新:如果你使用的是macOS Sierra,那么你可能需要再做一步,因为上面的步骤可能不再有效。在~/.ssh/config中添加以下命令:

Host *
  UseKeychain yes

使用SSH而不是HTTPS更新原始远程的url;

git remote set-url origin "SSH URL COPIED FROM GIT REPO."

这对我很管用。