我遇到了以下错误:

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

当前回答

Run

ssh-agent bash
ssh-add

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

ssh-agent

或运行

man ssh-agent

其他回答

让我提供另一种解决方案。如果您刚刚安装了Git 1.8.2.2或更高版本,并且希望启用SSH,请遵循写得好的说明。

一直到步骤5.6,您可能会遇到一个小障碍。如果SSH代理已经在运行,则在重新启动bash时可能会收到以下错误消息

Could not open a connection to your authentication agent

如果需要,请使用以下命令查看是否有多个ssh代理进程正在运行

ps aux | grep ssh

如果看到多个ssh代理服务,则需要终止所有这些进程。按如下方式使用kill命令(PID在您的计算机上是唯一的)

kill <PID>

例子:

kill 1074

删除所有ssh代理进程后,再次运行px aux | grep ssh命令以确保它们已删除,然后重新启动Bash。

瞧,你现在应该得到这样的东西:

Initializing new SSH agent...
succeeded
Enter passphrase for /c/Users/username/.ssh/id_rsa:

现在,您可以继续执行步骤5.7及更高的步骤。

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

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

放大n3o对Windows 7的回答。。。

我的问题是确实没有设置一些必需的环境变量,而n3o是正确的,ssh-agent会告诉您如何设置这些环境变量,但实际上并没有设置它们。

由于Windows不允许您执行“eval”,因此以下是替代方法:

将ssh代理的输出重定向到批处理文件

ssh-agent > temp.bat

现在使用记事本等文本编辑器编辑temp.bat。对于前两行中的每一行:

在行首插入单词“set”和空格。删除第一个分号和后面的所有内容。

现在删除第三行。您的temp.bat应该如下所示:

set SSH_AUTH_SOCK=/tmp/ssh-EorQv10636/agent.10636
set SSH_AGENT_PID=8608

运行temp.bat。这将设置ssh add工作所需的环境变量。

对于内置于Windows 10中的Bash,我将其添加到文件.Bash_profile中:

if [ -z $SSH_AUTH_SOCK ]; then
    if [ -r ~/.ssh/env ]; then
            source ~/.ssh/env
            if [ `ps -p $SSH_AGENT_PID | wc -l` = 1 ]; then
                    rm ~/.ssh/env
                    unset SSH_AUTH_SOCK
            fi
    fi
fi

if [ -z $SSH_AUTH_SOCK ]; then
    ssh-agent -s | sed 's/^echo/#echo/'> ~/.ssh/env
    chmod 600 ~/.ssh/env
    source ~/.ssh/env > /dev/null 2>&1
fi

“代理转发”是一种可以帮助您解决问题的技术。这使得本地SSH密钥在服务器内的活动会话期间“可用”。

如果您在Windows上使用PuTTY,则需要将“Connection/SSSH/Auth/Allow-agent forwarding”选项设置为“true”。