我遇到了以下错误:

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

当前回答

连接到服务器时使用参数-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.

其他回答

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

以下命令对我有效。我使用的是CentOS。

exec ssh-agent bash

这个解决方案很可能对你有用,再试一次

在我的例子中,它与DNS映射有关(bitbucket没有指向正确的IP)。我通过一个简单的技巧修复了它(在查找bitbucket.org时,我重写了IP地址)

在ubuntu中打开和编辑/etc/hosts(如果是任何其他操作系统,请查看如何做到这一点)

sudo vim /etc/hosts

并添加以下行(如果是GitHub或任何其他网站,请查找IP并相应地进行映射)

18.205.93.2 bitbucket.org

然后就能解决问题

当我启动ssh代理时,当它已经在运行时,我遇到了这个问题。多个实例似乎彼此冲突。

要查看ssh代理是否已在运行,请使用以下命令检查ssh_agent_SOCK环境变量的值:

echo $SSH_AGENT_SOCK

如果已设置,则代理程序可能正在运行。

要检查是否有多个ssh代理正在运行,可以查看:

ps -ef | grep ssh

当然,您应该终止创建的任何其他实例。

ssh-add和ssh(假设您使用的是openssh实现)需要一个环境变量来知道如何与ssh代理通信。如果在与当前使用的命令提示符窗口不同的命令提示符下启动代理,或者如果启动错误,ssh-add和ssh都不会看到该环境变量集(因为环境变量是在本地设置到其所在的命令提示符中的)。

你不知道你使用的是哪个版本的ssh,但如果你使用的cygwin,你可以在cygwin上使用ssh代理的这个配方:

# Add to your Bash config file
SSHAGENT=/usr/bin/ssh-agent
SSHAGENTARGS="-s"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
    eval `$SSHAGENT $SSHAGENTARGS`
    trap "kill $SSH_AGENT_PID" 0
fi

这将为您打开的每个新命令提示符窗口自动启动一个代理(如果您在一个会话中打开多个命令提示符,这是不太理想的,但至少它应该可以工作)。