我按照github教程中的指示创建了密钥,在github上注册了它们,并尝试显式地使用ssh-agent -然而,每当我尝试进行拉或推操作时,git仍然会继续询问我的密码。
原因可能是什么?
我按照github教程中的指示创建了密钥,在github上注册了它们,并尝试显式地使用ssh-agent -然而,每当我尝试进行拉或推操作时,git仍然会继续询问我的密码。
原因可能是什么?
当前回答
也许不是最安全的方法来解决这个问题,但不要设置密码短语,这是可选的。如果您不设置密码短语,它将不会请求它。你可以用更改密码
$ 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.
其他回答
如果上面的解决方案不适合我,需要检查的一件事是您实际上也有公钥(通常是id_rsa.pub)。不这样做很不寻常,但这就是我的原因。
从私钥创建公钥:
ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub
如果你没有使用GitBash并且在Windows上-你需要使用这个命令启动你的ssh-agent
start-ssh-agent.cmd
如果您的ssh代理没有设置,您可以以管理员身份打开PowerShell并将其设置为手动模式
Get-Service -Name ssh-agent | Set-Service -StartupType Manual
听起来您可能在SSH-Agent本身遇到了问题。我会试着排除故障。
1)你做SSH -add添加你的密钥到SSH?
2)你是否在使用之间关闭终端窗口,因为如果你关闭了窗口,当你重新打开它时,你将不得不再次输入密码。
上面没有提到的另一个可能的解决方案是使用以下命令检查您的遥控器:
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
如果你用的是Win10:
我也有同样的问题。 (以前由于不同的问题,必须从这里用脚本单独更新ssh-agent)
Git确实访问了我的ssh配置(当我在ssh配置中有无意义的行时,Git会抛出异常),但似乎从不关心我通过ssh-agent添加并在配置中引用的私钥。
解决问题的方法是在PowerShell中执行以下命令:
git config core.sshCommand (get-command ssh).Source.Replace('\','/')
(详情见此连结)