我遇到了以下错误:

$ 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用户,我发现cmd eval“ssh agent-s”不起作用,但使用Git Bash效果不错:

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

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

其他回答

这将只在您第一次需要时运行SSH代理并进行身份验证,而不是每次打开Bash终端时。它可以用于一般使用SSH的任何程序,包括SSH本身和scp。只需将其添加到/etc/profile.d/ssh-helper.sh:

ssh-auth() {
    # Start the SSH agent only if not running
    [[ -z $(ps | grep ssh-agent) ]] && echo $(ssh-agent) > /tmp/ssh-agent-data.sh

    # Identify the running SSH agent
    [[ -z $SSH_AGENT_PID ]] && source /tmp/ssh-agent-data.sh > /dev/null

    # Authenticate (change key path or make a symlink if needed)
    [[ -z $(ssh-add -l | grep "/home/$(whoami)/.ssh/id_rsa") ]] && ssh-add
}

# You can repeat this for other commands using SSH
git() { ssh-auth; command git "$@"; }

注:这是对这个问题的回答,它已经与这个问题合并。这个问题是针对Windows 7的,这意味着我的答案是针对Cygwin/MSYS/MSYS2的。这一点似乎适用于某些Unix,我不希望SSH代理需要这样管理。

我在Ubuntu上遇到了同样的问题,其他的解决方案对我没有帮助。

我终于意识到我的问题是什么。我在/root/.SSH文件夹中创建了我的SSH密钥,所以即使我以root身份运行SSH-add,它也无法正常工作,一直在说:

无法打开与身份验证代理的连接。

我在/home/myUsername/文件夹中创建了SSH公钥和私钥

ssh-agent /bin/sh

然后我跑了

ssh-add /home/myUsername/.ssh/id_rsa

问题就这样解决了。

注意:要访问Git中的存储库,请在使用SSH keygen-t rsa-C“您的Git电子邮件”创建SSH密钥时添加Git密码。

放大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工作所需的环境变量。

这对我有用。

在CMD窗口中,键入以下命令:

cd path-to-Git/bin # (for example,cd C:\Program Files\Git\bin)
bash
exec ssh-agent bash
ssh-add path/to/.ssh/id_rsa

我没有使用ssh代理-s,而是使用eval“ssh代理-s”来解决这个问题。

下面是我一步一步执行的操作(在GitBash上执行第2步):

清理了位于C:\user\<username>\.ssh的.ssh文件夹\生成了新的SSH密钥:ssh keygen-t rsa-b 4096-C“xyz@abc.com"检查是否有任何进程id(ssh代理)正在运行。ps aux | grep ssh(可选)如果在步骤3中发现任何错误,请清除这些错误杀死<pids>已启动SSH代理$eval` ssh代理-s `将步骤2中生成的SSH密钥添加到SSH代理ssh添加~/.ssh/id_rsa