我遇到了以下错误:

$ 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上运行以通过SSH连接到存储库时,我也遇到了类似的问题。

这是对我有效的解决方案。

原来我在我的Windows盒子上运行Pageant ssh代理-我会检查你在运行什么。我怀疑它是Pageant,因为它是PuTTY和WinSCP的默认值。ssh add不能在命令行中使用这种类型的代理您需要通过Pageant UI窗口添加私钥,双击任务栏中的Pageant图标(启动后)即可获得该窗口。在将密钥添加到Pageant之前,需要将其转换为PPK格式。此处提供了完整的说明如何将SSH密钥转换为ppk格式就是这样。一旦我将密钥上传到存储库,我就可以使用Sourcetree创建本地存储库并克隆远程。

其他回答

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

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

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

尝试以下操作:

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

Run

ssh-agent bash
ssh-add

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

ssh-agent

或运行

man ssh-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存储库,而无需手动输入密码。