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

原因可能是什么?


当前回答

似乎您的本地repo没有更新ssh密钥…至少这是我从HTTPS到ssh时遇到的情况。

你远程重置了吗?

git remote set-url origin <ssh url>

其他回答

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

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

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

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

我尝试了不同的解决方案,但都没用。但是这个步骤(我的giitbash SSH环境总是要求我的密码,我能做什么?)从Bitbucket.com接缝工作得很好:

这个想法是:

you create ~/.bashrc file add follow script: SSH_ENV=$HOME/.ssh/environment # start the ssh-agent function start_agent { echo "Initializing new SSH agent..." # spawn ssh-agent /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}" echo succeeded chmod 600 "${SSH_ENV}" . "${SSH_ENV}" > /dev/null /usr/bin/ssh-add } if [ -f "${SSH_ENV}" ]; then . "${SSH_ENV}" > /dev/null ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { start_agent; } else start_agent; fi re-run Bash

以前-K标志用于添加键,但现在:

ssh-add --apple-use-keychain

-K和-A标志已弃用,已被替换 用苹果使用钥匙链和苹果装载钥匙链 分别标记。


稍后编辑:您可能需要添加ssh-add——apple-load-keychain -q到您的.bash_profile或.bashrc或.zshrc或等效文件。

在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