我遇到了以下错误:

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

当前回答

你启动ssh代理了吗?

在运行ssh-add命令之前,可能需要启动ssh代理:

eval `ssh-agent -s`
ssh-add

注意,这将在Windows上启动msysgit Bash的代理。如果您使用的是不同的shell或操作系统,则可能需要使用命令的变体,例如其他答案中列出的那些。

请参阅以下答案:

ssh-add抱怨:无法打开与身份验证代理的连接Git推送需要用户名和密码(包含如何使用ssh代理的详细说明)如何运行(git/ssh)身份验证代理?。无法打开与身份验证代理的连接

要自动启动ssh代理并允许单个实例在多个控制台窗口中工作,请参阅登录时启动ssh代理。

为什么我们需要使用eval而不仅仅是ssh代理?

SSH需要两件事才能使用SSH-agent:一个在后台运行的SSH-agent实例,以及一个环境变量集,该环境变量集告诉SSH应该使用哪个套接字连接到代理(SSH_AUTH_SOCK IIRC)。如果您只运行ssh代理,那么代理将启动,但ssh不知道在哪里可以找到它。

从这个评论中。

公钥与私钥

此外,每当我使用ssh-add时,我总是向其中添加私钥。文件~/.ssh/id_rsa.pub看起来像公钥,我不确定这是否有效。您有~/.ssh/id_rsa文件吗?如果你在文本编辑器中打开它,它会说它是私钥吗?

其他回答

尝试执行以下步骤:

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

连接到服务器时使用参数-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用户,我发现cmd eval“ssh agent-s”不起作用,但使用Git Bash效果不错:

eval `ssh-agent -s`; ssh-add KEY_LOCATION

并确保Windows服务“OpenSSH密钥管理”未被禁用。

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

exec ssh-agent bash

在Windows 8.1 E上使用Git Bash,我的解决方案如下:

eval $(ssh-agent) > /dev/null
ssh-add ~/.ssh/id_rsa