我遇到了以下错误:

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

当前回答

尝试执行以下步骤:

打开GitBash并运行:cd~/.ssh尝试运行agent:eval$(ssh代理)现在,您可以运行以下命令:ssh-add-l

其他回答

放大n3o对Windows 7的回答。。。

我的问题是确实没有设置一些必需的环境变量,而n3o是正确的,ssh-agent会告诉您如何设置这些环境变量,但实际上并没有设置它们。

由于Windows不允许您执行“eval”,因此以下是替代方法:

将ssh代理的输出重定向到批处理文件

ssh-agent > temp.bat

现在使用记事本等文本编辑器编辑temp.bat。对于前两行中的每一行:

在行首插入单词“set”和空格。删除第一个分号和后面的所有内容。

现在删除第三行。您的temp.bat应该如下所示:

set SSH_AUTH_SOCK=/tmp/ssh-EorQv10636/agent.10636
set SSH_AGENT_PID=8608

运行temp.bat。这将设置ssh add工作所需的环境变量。

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

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

尝试以下操作:

ssh-agent sh -c 'ssh-add && git push heroku master'

在Windows 10中,我尝试了这里列出的所有答案,但似乎没有一个有效。事实上,他们给出了一个线索。要解决问题,只需要三个命令。这个问题的想法是ssh add需要使用当前ssh代理SOCK文件路径和PID号设置ssh_AUTH_SOCK和ssh_AGENT_PID环境变量。

ssh-agent -s > temp.txt

这将把ssh代理的输出保存在一个文件中。文本文件内容如下:

SSH_AUTH_SOCK=/tmp/ssh-kjmxRb2764/agent.2764; export SSH_AUTH_SOCK;
SSH_AGENT_PID=3044; export SSH_AGENT_PID;
echo Agent pid 3044;

从文本文件中复制类似“/tmp/ssh-kjmxRb2764/agent.2764”的内容,并直接在控制台中运行以下命令:

set SSH_AUTH_SOCK=/tmp/ssh-kjmxRb2764/agent.2764

从文本文件中复制类似“3044”的内容,并直接在控制台中运行以下命令:

set SSH_AGENT_PID=3044

现在,当为当前控制台会话设置了环境变量(SSH_AUTH_SOCK和SSH_AGENT_PID)时,运行SSH add命令,连接到SSH代理不会再次失败。

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