我遇到了以下错误:

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

当前回答

阅读用户456814的答案以获得解释。这里我只尝试自动修复。

如果您在Bash中使用Cygwin终端,请将以下内容添加到$HOME/.bashrc文件中。这只会在第一个Bash终端中启动一次ssh代理,并将密钥添加到ssh代理。(我不确定Linux上是否需要这样做。)

###########################
# start ssh-agent for
# ssh authentication with github.com
###########################
SSH_AUTH_SOCK_FILE=/tmp/SSH_AUTH_SOCK.sh
if [ ! -e $SSH_AUTH_SOCK_FILE ]; then
    # need to find SSH_AUTH_SOCK again.
    # restarting is an easy option
    pkill ssh-agent
fi
# check if already running
SSH_AGENT_PID=`pgrep ssh-agent`
if [ "x$SSH_AGENT_PID" == "x" ]; then
#   echo "not running. starting"
    eval $(ssh-agent -s) > /dev/null
    rm -f $SSH_AUTH_SOCK_FILE
    echo "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK" > $SSH_AUTH_SOCK_FILE
    ssh-add $HOME/.ssh/github.com_id_rsa 2>&1 > /dev/null
#else
#   echo "already running"
fi
source $SSH_AUTH_SOCK_FILE

不要忘记在“ssh-add”命令中添加正确的密钥。

其他回答

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

要解决此错误,请执行以下操作:

猛击:

$ eval `ssh-agent -s`

tcsh:

$ eval `ssh-agent -c`

然后像平常一样使用ssh-add。


热门提示:

我总是忘记为上面的ssh代理命令键入什么,所以我在.bashrc文件中创建了一个别名,如下所示:

alias ssh-agent-cyg='eval `ssh-agent -s`'

现在,我可以使用ssh代理cyg代替ssh代理

E.g.

$ ssh-agent-cyg
SSH_AUTH_SOCK=/tmp/ssh-n16KsxjuTMiM/agent.32394; export SSH_AUTH_SOCK;
SSH_AGENT_PID=32395; export SSH_AGENT_PID;
echo Agent pid 32395;
$ ssh-add ~/.ssh/my_pk

原始修复源:

http://cygwin.com/ml/cygwin/2011-10/msg00313.html

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

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

Run

ssh-agent bash
ssh-add

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

ssh-agent

或运行

man ssh-agent

尝试以下操作:

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

运行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代理进程而言,这是相同的事情。