在终端中,如何将主机密钥添加到known_hosts文件中?


3

在终端中,如何将主机密钥添加到known_hosts文件中?另外,如何从同一个文件中删除给定的主机密钥?

我试图在我的学校和我输入命令时进入计算机 johndoe@mu.math.umn.edu,它返回:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
fb:59:b6:4f:e0:9d:99:64:12:44:c8:16:1c:46:b0:92.
Please contact your system administrator.
Add correct host key in /Users/johndoe/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/johndoe/.ssh/known_hosts:1
RSA host key for mu.math.umn.edu has changed and you have requested strict checking.
Host key verification failed.

我不确定,但我想我想要做的是将这个“指纹RSA密钥”添加到文件known_hosts。

Answers:


4

您可以使用任何文本编辑器进行编辑 ~/.ssh/known_hosts 如nano或vi。使用格式......

serverIP ssh-rsa key

根据编辑过的问题,您似乎在文件中有一个无效密钥,该密钥与主机提供的密钥不一致。一个简单的解决方法是在任何文本编辑器中打开〜/ .ssh / known_hosts,删除整个第1行(如错误中的“known_hosts:1”所示),保存文件并尝试再次连接。这次,系统将提示您添加密钥,它将自动添加。

known_hosts文件存储主机的密钥,以确认您连接的主机是预期的主机。当主机更改密钥时,它会阻止所有连接,因为预期密钥不匹配。您需要删除旧密钥,下次尝试连接时将自动添加新密钥。


所以这是我需要在文本编辑器中做的事情,而不是终端?
Sam

@Itried根据您添加的相关信息编辑回答。
grg

好的,我安装了一个文本编辑器。现在如何在MacVim中打开该文件?
Sam

@Itried我对MacVim没有任何经验。我建议你使用TextEdit open ~/.ssh/known_hosts 或纳米 nano ~/.ssh/known_hosts,两者都是预装的。
grg
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.