我遇到了以下错误:

$ 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 10中,使用命令提示符终端,以下功能适用于我:

ssh-agent cmd 
ssh-add

然后应要求您在此之后输入密码:

Enter passphrase for /c/Users/username/.ssh/id_rsa:

其他回答

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

我犯了一个非常重要且愚蠢的错误——没有在~/.ssh文件夹中生成密钥。在开始github上描述的所有步骤之前,请更改为~/.ssh。这解决了我的问题

https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

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

这对我有用。

在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