如果缺少/root/.ssh/known_hosts文件,这是否很糟糕?

时间:2019-11-24 22:26:25

标签: ssh ssh-keys

就像标题所示,我尝试连接到服务器(身份验证工作正常),但在启动时始终会显示此提示。

屏幕:http://prntscr.com/q1hq69

那很糟糕,我该如何解决?

1 个答案:

答案 0 :(得分:-1)

SSH每当连接到新服务器时,都会执行称为服务器白名单的操作。该白名单称为known_hosts,并存储在$HOME/.ssh/中。如果没有的话没什么大不了的,它应该始终向您显示Are you sure you want to continue connecting (yes/no)?提示。

您可以尝试通过运行以下命令来解决此问题:

ssh-keyscan -H remote-host >> ~/.ssh/known_hosts

 ➜  (24/11 23:56) /tmp ssh-keyscan -H github.com >> ~/.ssh/known_hosts
# github.com:22 SSH-2.0-babeld-2e9d163d
# github.com:22 SSH-2.0-babeld-2e9d163d
# github.com:22 SSH-2.0-babeld-2e9d163d
  

SSH进程的背景

SSH通常在用户连接到不在列表中的服务器时提示用户一个安全问题。

 ➜  (24/11 23:41) /tmp ssh -T git@github.com
The authenticity of host 'github.com (140.82.118.4)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
Hi praveenprem! You've successfully authenticated, but GitHub does not provide shell access.

这简直是在问您是否信任远程服务器。说出yes,将在<{1}文件中添加 github.com 及其指纹以供将来参考,并且不再提示。 >

唯一的例外是,如果远程服务器的指纹发生更改,则SSH将承担中间人攻击并提示此消息。

known_hosts

这是您唯一需要关注的时刻,非常小心如何解决此问题,因为这可能是两件事之一:

  1. 实际的中间人攻击
  2. 远程服务器的密钥已重新生成。只需删除输出中引用的行即可解决此问题。