我遇到了以下错误:

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

当前回答

我在尝试下载Git存储库时出错:

无法打开与身份验证代理的连接。ssh添加退出代码2

要消除此错误,请执行以下操作:

使用无密码私钥时,既不需要ssh代理,也不需要ssh add。请参阅将私钥添加到docker文件中的ssh代理。

如果处理得当(使用后删除),无密码私钥不需要使系统不安全。也许这也有助于解决Heroku问题?


这个“把戏”什么时候最重要?在Dockerfile中!

我必须使用无密码私钥来获取Dockerfile以克隆Git存储库,因为在Dockerfile运行期间,无法在shell中输入密码。请参阅Dockerfile:clone repo with passwordless private key。错误:例如,“身份验证代理”或“read_passphrase:无法打开/dev/tty”。最近,还可以考虑使用部署令牌访问Git存储库,而无需手动输入密码。

其他回答

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

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

echo $SSH_AGENT_SOCK

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

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

ps -ef | grep ssh

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

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

exec ssh-agent bash

运行ssh代理的基本解决方案有很多答案。然而,多次运行ssh代理(每个打开的终端或每个远程登录)将创建内存中运行的ssh代理的多个副本。建议避免该问题的脚本很长,需要编写和/或复制分离的文件,或者需要在~/.profile或~/.src中编写太多字符串。让我建议简单的双字符串解决方案:

对于sh、bash等:

# ~/.profile
if ! pgrep -q -U `whoami` -x 'ssh-agent'; then ssh-agent -s > ~/.ssh-agent.sh; fi
. ~/.ssh-agent.sh

对于csh、tcsh等:

# ~/.schrc
sh -c 'if ! pgrep -q -U `whoami` -x 'ssh-agent'; then ssh-agent -c > ~/.ssh-agent.tcsh; fi'
eval `cat ~/.ssh-agent.tcsh`

这里有什么:

按名称和当前用户搜索进程ssh代理通过调用ssh代理创建适当的shell脚本文件,如果未找到当前用户ssh代理进程,则自行运行ssh代理评估已创建的配置适当环境的shell脚本

不必保护创建的shell脚本~/.sh-agent.tcsh或~/.sshagent.sh不受其他用户访问,因为:首先,与ssh代理的通信是通过受保护的套接字进行的,其他用户无法访问该套接字,其次,其他用户可以通过/tmp/目录中的枚举文件找到简单的ssh代理套接字。就访问ssh代理进程而言,这是相同的事情。

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

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

chgrp Users id_rsa

以及

chmod 600 id_rsa

最后我能够使用:

ssh-agent ssh-add 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.