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

原因可能是什么?


当前回答

上面没有提到的另一个可能的解决方案是使用以下命令检查您的遥控器:

git remote -v

如果远程服务器不是以git启动,而是以https启动,您可能希望按照下面的示例将其更改为git。

git remote -v // origin is https://github.com/user/myrepo.git
git remote set-url origin git@github.com:user/myrepo.git
git remote -v // check if remote is changed

其他回答

听起来您可能在SSH-Agent本身遇到了问题。我会试着排除故障。

1)你做SSH -add添加你的密钥到SSH?

2)你是否在使用之间关闭终端窗口,因为如果你关闭了窗口,当你重新打开它时,你将不得不再次输入密码。

也许不是最安全的方法来解决这个问题,但不要设置密码短语,这是可选的。如果您不设置密码短语,它将不会请求它。你可以用更改密码

$ 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.

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

在Windows上对我有效的是(我从repo 1st中克隆了代码):

eval $(ssh-agent)
ssh-add 
git pull 

这时它最后一次向我要密码

积分:溶液是从 https://unix.stackexchange.com/questions/12195/how-to-avoid-being-asked-passphrase-each-time-i-push-to-bitbucket

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

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

Host *
  UseKeychain yes