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

原因可能是什么?


当前回答

如果你碰巧用的是鱼,这里有一个要点:

# config.fish
if not pgrep -f ssh-agent > /dev/null
  eval (ssh-agent -c)
  set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK
  set -Ux SSH_AGENT_PID $SSH_AGENT_PID
  set -Ux SSH_AUTH_SOCK $SSH_AUTH_SOCK
end

其他回答

如果你没有使用GitBash并且在Windows上-你需要使用这个命令启动你的ssh-agent

start-ssh-agent.cmd

如果您的ssh代理没有设置,您可以以管理员身份打开PowerShell并将其设置为手动模式

Get-Service -Name ssh-agent | Set-Service -StartupType Manual

使用SSH而不是HTTPS更新原始远程的url;

git remote set-url origin "SSH URL COPIED FROM GIT REPO."

这对我很管用。

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

ssh-add --apple-use-keychain

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


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

在mac上, 如果你的SSH密钥每次都需要密码,你想跳过它,那么你可以试试下面,它对我来说很好

Eval "$(ssh-agent -s)" ssh-add -K .ssh/id_rsa 添加这个默认的SSH配置对我有用

主机* AddKeysToAgent是的 UseKeychain是的 IdentityFile ~ / . ssh / id_rsa

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

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