我遇到了以下错误:

$ 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。请参阅无法打开与身份验证代理的连接。

让我提供另一种解决方案。如果您刚刚安装了Git 1.8.2.2或更高版本,并且希望启用SSH,请遵循写得好的说明。

一直到步骤5.6,您可能会遇到一个小障碍。如果SSH代理已经在运行,则在重新启动bash时可能会收到以下错误消息

Could not open a connection to your authentication agent

如果需要,请使用以下命令查看是否有多个ssh代理进程正在运行

ps aux | grep ssh

如果看到多个ssh代理服务,则需要终止所有这些进程。按如下方式使用kill命令(PID在您的计算机上是唯一的)

kill <PID>

例子:

kill 1074

删除所有ssh代理进程后,再次运行px aux | grep ssh命令以确保它们已删除,然后重新启动Bash。

瞧,你现在应该得到这样的东西:

Initializing new SSH agent...
succeeded
Enter passphrase for /c/Users/username/.ssh/id_rsa:

现在,您可以继续执行步骤5.7及更高的步骤。

我通过强制停止(终止)git进程(ssh代理),然后卸载git,然后再次安装git来解决这个错误。

连接到服务器时使用参数-A,例如:

ssh -A root@myhost

来自手册页:

-A Enables forwarding of the authentication agent connection.  
   This can also be specified on a per-host basis in a configuration file.

   Agent forwarding should be enabled with caution.  Users with the ability to bypass file permissions on the remote host (for the agent's
   UNIX-domain socket) can access the local agent through the forwarded 
   connection.  An attacker cannot obtain key material from the agent,
   however they can perform operations on the keys that enable them to
   authenticate using the identities loaded into the agent.

“代理转发”是一种可以帮助您解决问题的技术。这使得本地SSH密钥在服务器内的活动会话期间“可用”。

如果您在Windows上使用PuTTY,则需要将“Connection/SSSH/Auth/Allow-agent forwarding”选项设置为“true”。