每次我使用git与遥控器交互时,比如拉或推时,我都会看到以下消息:

警告:永久添加'…' (RSA)到已知主机列表。

如何防止显示这个烦人的消息?这只是一个烦恼——一切都很正常。


当前回答

当我开始使用Windows电脑时,我也遇到了同样的问题。在我的例子中,这是因为我的SSH设置没有完成。Github有一个关于SSH设置的非常精确的文档。一旦解决了这个问题,问题就解决了。

https://help.github.com/articles/checking-for-existing-ssh-keys/ https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

其他回答

将您的私钥添加到ssh-agent:

ssh-add ~/.ssh/id_rsa

要屏蔽ssh的警告消息,可以在~/.ssh/config中添加以下行:

Host *
LogLevel error

这将禁用警告,但不会禁用错误消息。就像~/中的其他设置一样。如果你想要一个更细粒度的控制,你可以在每个主机上配置LogLevel。

这主要意味着该主机的键发生了变化~/。ssh/known_hosts,它不会自动更新它。因此,每当您收到此警告消息时。

这种情况经常发生在连接到重新创建的虚拟机时,它会使用相同的IP地址更改密钥

解决方案

如果只有一个条目,那么可以删除~/。Ssh /known_hosts文件,并且在第一次连接之后,密钥将在那里,之后没有警告消息。

如果有多个条目,则可以使用下面的命令删除

$ ssh-keygen -R <hostname>

这对我来说很有效

我的情况下,我只得到ssh警告时使用Gridengine qrsh远程shell登录。然而,正常的ssh会像预期的那样工作(第一次发出警告,然后在随后的时间里保持安静)。

我的解决方案是手动填充~/。ssh/known_hosts与Gridengine可以选择的所有可能的服务器名称(使用qhost列出服务器):

for p in server1 server2 server3 server4; do
  ssh-keyscan -H ${p}.company.com;
  ssh-keyscan -H $(getent hosts $p | perl -lane 'print $F[0]');
done >> ~/.ssh/known_hosts

背景:

Gridengine is a job scheduler which can use ssh to select the least loaded server. The reason for the warning is that qrsh seem to always specify a non-standard port for doing the ssh connection, causing known_hosts to be updated with an entry also containing a port number. Next time when qrsh selects the same server there would be a new port-number and known_hosts would get updated with a new port-specific entry. The reason for also adding the raw host IP address is that some hosts used ecdsa-sha2-nistp521. If a raw IP entry is not added I would get the warning:

ECDSA host key for IP address '10.1.2.3' not in list of known hosts.

在ssh配置文件($HOME/.ssh/config)中添加以下行:

LogLevel=quiet

如果从命令行运行ssh,在命令字符串中添加以下选项:

-o LogLevel=quiet

例如,下面打印在machine.example.org上安装的gcc版本(没有警告):

ssh -o UserKnownHostsFile=/dev/null \
    -o StrictHostKeyChecking=no \
    -o LogLevel=quiet \
    -i identity_file \
    machine.example.org \
    gcc -dumpversion