我按照github教程中的指示创建了密钥,在github上注册了它们,并尝试显式地使用ssh-agent -然而,每当我尝试进行拉或推操作时,git仍然会继续询问我的密码。
原因可能是什么?
我按照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
其他回答
以前-K标志用于添加键,但现在:
ssh-add --apple-use-keychain
-K和-A标志已弃用,已被替换 用苹果使用钥匙链和苹果装载钥匙链 分别标记。
稍后编辑:您可能需要添加ssh-add——apple-load-keychain -q到您的.bash_profile或.bashrc或.zshrc或等效文件。
如果上面的解决方案不适合我,需要检查的一件事是您实际上也有公钥(通常是id_rsa.pub)。不这样做很不寻常,但这就是我的原因。
从私钥创建公钥:
ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
我不知道是否有人需要不同的东西,但这对我帮助很大 https://stackoverflow.com/a/6445525/11891580
对我来说,每次重启,我都必须运行ssh-add——apple-use-keychain来加载凭据,所以我把这个命令添加到堆栈溢出的答案,现在它已经修复了
我尝试了不同的解决方案,但都没用。但是这个步骤(我的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
如果你用的是Win10:
我也有同样的问题。 (以前由于不同的问题,必须从这里用脚本单独更新ssh-agent)
Git确实访问了我的ssh配置(当我在ssh配置中有无意义的行时,Git会抛出异常),但似乎从不关心我通过ssh-agent添加并在配置中引用的私钥。
解决问题的方法是在PowerShell中执行以下命令:
git config core.sshCommand (get-command ssh).Source.Replace('\','/')
(详情见此连结)