我遇到了以下错误:

$ 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中的PowerShell

我在使用PowerShell和Start-SshAgent/Add-SshKey命令时遇到了问题,所以我快速编写了一个脚本,可能会帮助一些人。这将添加到PowerShell配置文件中,您可以通过执行记事本$profile来编辑该配置文件:

if ($(Get-Process ssh-agent) -eq $null)
{
     $ExecutionContext.InvokeCommand.ExpandString($(ssh-agent -c).Replace("setenv", "set"));
}

它将检测ssh代理是否正在运行,并且仅在没有代理运行时执行。请注意,$ExecutionContext.InvokeCommand.ExpandString是一个非常危险的命令,因此如果您使用的是不受信任的ssh代理副本,则可能不希望使用此解决方案。

其他回答

我尝试了其他解决方案,但都没有效果。我做了更多的研究,发现以下命令有效。我正在使用Windows 7和Git Bash。

eval $(ssh-agent)

更多信息:https://coderwall.com/p/rdi_wq(web存档版本)

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

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

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

在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代理不会再次失败。

我没有使用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