我遇到了以下错误:

$ git push heroku master
Warning: Permanently added the RSA host key for IP address '50.19.85.132' to the list of known hosts.
!  Your key with fingerprint b7:fd:15:25:02:8e:5f:06:4f:1c:af:f3:f0:c3:c2:65 is not authorized to access bitstarter.

我尝试添加密钥,但出现以下错误:

$ ssh-add ~/.ssh/id_rsa.pub
Could not open a connection to your authentication agent.

当前回答

在Windows 8.1 E上使用Git Bash,我的解决方案如下:

eval $(ssh-agent) > /dev/null
ssh-add ~/.ssh/id_rsa

其他回答

我在Linux上遇到了同样的问题,下面是我所做的:

基本上,命令ssh-agent启动代理,但它并没有真正设置运行环境变量。它只是将这些变量输出到shell。

您需要:

eval `ssh-agent`

然后执行ssh-add。请参阅无法打开与身份验证代理的连接。

我在Ubuntu上遇到了同样的问题,其他的解决方案对我没有帮助。

我终于意识到我的问题是什么。我在/root/.SSH文件夹中创建了我的SSH密钥,所以即使我以root身份运行SSH-add,它也无法正常工作,一直在说:

无法打开与身份验证代理的连接。

我在/home/myUsername/文件夹中创建了SSH公钥和私钥

ssh-agent /bin/sh

然后我跑了

ssh-add /home/myUsername/.ssh/id_rsa

问题就这样解决了。

注意:要访问Git中的存储库,请在使用SSH keygen-t rsa-C“您的Git电子邮件”创建SSH密钥时添加Git密码。

我没有使用ssh代理-s,而是使用eval“ssh代理-s”来解决这个问题。

下面是我一步一步执行的操作(在GitBash上执行第2步):

清理了位于C:\user\<username>\.ssh的.ssh文件夹\生成了新的SSH密钥:ssh keygen-t rsa-b 4096-C“xyz@abc.com"检查是否有任何进程id(ssh代理)正在运行。ps aux | grep ssh(可选)如果在步骤3中发现任何错误,请清除这些错误杀死<pids>已启动SSH代理$eval` ssh代理-s `将步骤2中生成的SSH密钥添加到SSH代理ssh添加~/.ssh/id_rsa

这将只在您第一次需要时运行SSH代理并进行身份验证,而不是每次打开Bash终端时。它可以用于一般使用SSH的任何程序,包括SSH本身和scp。只需将其添加到/etc/profile.d/ssh-helper.sh:

ssh-auth() {
    # Start the SSH agent only if not running
    [[ -z $(ps | grep ssh-agent) ]] && echo $(ssh-agent) > /tmp/ssh-agent-data.sh

    # Identify the running SSH agent
    [[ -z $SSH_AGENT_PID ]] && source /tmp/ssh-agent-data.sh > /dev/null

    # Authenticate (change key path or make a symlink if needed)
    [[ -z $(ssh-add -l | grep "/home/$(whoami)/.ssh/id_rsa") ]] && ssh-add
}

# You can repeat this for other commands using SSH
git() { ssh-auth; command git "$@"; }

注:这是对这个问题的回答,它已经与这个问题合并。这个问题是针对Windows 7的,这意味着我的答案是针对Cygwin/MSYS/MSYS2的。这一点似乎适用于某些Unix,我不希望SSH代理需要这样管理。

甚至在生成和添加SSH密钥时运行命令时,我也收到了“无法打开到您的身份验证代理的连接”:SSH-add~/.SSH/id_rsa。

我通过停止在我的计算机上运行的多个ssh代理实例来解决这个问题,然后从我的Windows计算机上的控制面板卸载Git,然后再次安装Git,现在一切都正常了。