Skip to content

Instantly share code, notes, and snippets.

@tcpdump-examples
Last active February 4, 2022 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcpdump-examples/cbc515abec3f2c18ba1993e47eb1f1c0 to your computer and use it in GitHub Desktop.
Save tcpdump-examples/cbc515abec3f2c18ba1993e47eb1f1c0 to your computer and use it in GitHub Desktop.

什么是known_hosts文件

A通过ssh首次连接到B,B会将公钥1(host key)传递给A,A将公钥1存入known_hosts文件中,以后A再连接B时,B依然会传递给A一个公钥2,OpenSSH会核对公钥,通过对比公钥1与公钥2 是否相同来进行简单的验证,如果公钥不同,OpenSSH会发出警告, 避免你受到DNS Hijack之类的攻ji。。

打开known_hosts文件

vi ~/.ssh/known_hosts 或 vi /root/.ssh/known_hosts host文件内容格式:ip 公钥

了解更多ssh known_host

Host key verification failed

三、A通过ssh登陆B时提示 Host key verification failed 了解更多how to fix Host key verification failed

原因:A的known_hosts文件中记录的B的公钥1 与 连接时B传过来的公钥2不匹配

解决方法:

方法一:删除A的known_hosts文件中记录的B的公钥(手动进行,不适用于自动化部署情形) 有两只方法删除

  1. 通过vi 找到这个对应的ip或者host的host key 然后删除
  2. 通过ssh-keygen -r hostname 删除

方法二:修改配置文件,在ssh登陆时不通过known_hosts文件进行验证(安全性有所降低), 也是有两种方法:

  1. 编辑对应host的ssh配置文件 vi ~/.ssh/config //编辑配置文件 添加以下两行代码: StrictHostKeyChecking no
  2. 在ssh登录时利用 -i StrictHostKeyChecking=no 这样就不会检查host key。

如何解决fix too many authentication failures

如何处理remote host identification has changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment