我遇到了以下错误:

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

其他回答

以下是我在使用PowerShell时提出的解决方案。

将以下函数添加到Microsoft.PowerShell_profile.ps1

function RunSsh($userIdentity ) {
   $agent=ssh-agent
   $position=$agent[0].IndexOf("=")
   $ending=$agent[0].IndexOf(";")

   $variableStartPosition=$agent[0].IndexOf("export")
   $variableEndPosition=$agent[0].LastIndexOf(";")
   $variableName=$agent[0].Substring($variableStartPosition+7,$variableEndPosition-$variableStartPosition-7)
   [Environment]::SetEnvironmentVariable($variableName, $agent[0].Substring($position+1,$ending-$position-1))

   $position=$agent[1].IndexOf("=")
   $ending=$agent[1].IndexOf(";")

   $variableStartPosition=$agent[1].IndexOf("export")
   $variableEndPosition=$agent[1].LastIndexOf(";")
   $variableName=$agent[1].Substring($variableStartPosition+7,$variableEndPosition-$variableStartPosition-7)
   [Environment]::SetEnvironmentVariable($variableName, $agent[1].Substring($position+1,$ending-$position-1))

   if($userIdentity.Length -eq 0) {
      ssh-add
   } else {
      ssh-add $userIdentity
   }
}

现在,您可以从命令行运行RunSsh,它使用~\.ssh文件夹中的标识文件,或者使用RunSsh C:\ssh\id_rsa传递标识文件,其中C:\ssh\ id_rsa是您的标识文件。

要实现这一点,您需要在路径环境变量中使用ssh-add和ssh-agent。

我遇到的一件事是,eval对我使用Cygwin不起作用,对我起作用的是ssh代理ssh add id_rsa。

之后,我遇到了一个问题,我的私钥太开放了,我设法找到了解决方案(从这里):

chgrp Users id_rsa

以及

chmod 600 id_rsa

最后我能够使用:

ssh-agent ssh-add id_rsa

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

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

echo $SSH_AGENT_SOCK

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

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

ps -ef | grep 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.

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