我按照github教程中的指示创建了密钥,在github上注册了它们,并尝试显式地使用ssh-agent -然而,每当我尝试进行拉或推操作时,git仍然会继续询问我的密码。
原因可能是什么?
我按照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代理,使用:
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
如果上面的解决方案不适合我,需要检查的一件事是您实际上也有公钥(通常是id_rsa.pub)。不这样做很不寻常,但这就是我的原因。
从私钥创建公钥:
ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
似乎您的本地repo没有更新ssh密钥…至少这是我从HTTPS到ssh时遇到的情况。
你远程重置了吗?
git remote set-url origin <ssh url>
从OS X El Capitan(10.11)升级到macOS Sierra(10.12)后重新启动后,这种情况一直发生在我身上。ssh-add解决方案暂时有效,但不会在再次重新启动时继续存在。
永久的解决方案是编辑(或创建)~/。ssh/config,启用UseKeychain选项。
Host *
UseKeychain yes
相关:自从我更新到Sierra, macOS一直在问我的ssh密码
在mac上, 如果你的SSH密钥每次都需要密码,你想跳过它,那么你可以试试下面,它对我来说很好
Eval "$(ssh-agent -s)" ssh-add -K .ssh/id_rsa 添加这个默认的SSH配置对我有用
主机* AddKeysToAgent是的 UseKeychain是的 IdentityFile ~ / . ssh / id_rsa