我遇到了以下错误:

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

当前回答

这对我有用。

在CMD窗口中,键入以下命令:

cd path-to-Git/bin # (for example,cd C:\Program Files\Git\bin)
bash
exec ssh-agent bash
ssh-add path/to/.ssh/id_rsa

其他回答

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

MsysGit或Cygwin

如果您使用的是Msysgit或Cygwin,您可以在SSH代理中找到一个很好的教程:Msysgit、Cygwin和bash:

将名为.bashrc的文件添加到主文件夹。打开文件并粘贴到:#!/bin/basheval`ssh代理-s`ssh添加这假设您的密钥位于传统的~/.ssh/id_rsa位置。如果不是,请在ssh-add命令后包含完整路径。添加到或创建包含内容的文件~/.ssh/configForwardAgent是在最初的教程中,ForwardAgent参数是Yes,但它是一个拼写错误。使用小写字母,否则会出现错误。重新启动Msysgit。它会要求您输入一次密码,就这样(直到您结束会话,或者您的ssh代理被终止)

Mac/OS X

如果您不想在每次打开终端时启动新的ssh代理,请查看Keychain。我现在使用的是Mac,所以我在Mac OS X上使用了带有zsh&keychain的ssh代理教程来设置它,但我相信谷歌搜索会有很多关于Windows的信息。

更新:Mac上更好的解决方案是将密钥添加到Mac OS钥匙链:

ssh-add -K ~/.ssh/id_rsa

就这么简单。

在我的情况下,我的Comodo防火墙已将ssh代理装箱。一旦我禁用了沙盒,我就能够克隆存储库。

仅供参考,我正在Windows 7上使用Comodo防火墙。

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

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

Run

ssh-agent bash
ssh-add

要获取更多详细信息,您可以搜索

ssh-agent

或运行

man ssh-agent