zoukankan      html  css  js  c++  java
  • ssh stricthostkeychecking=0

    SSH 公钥检查是一个重要的安全机制,可以防范中间人劫持等黑客攻击。

    但是在特定情况下,严格的 SSH 公钥检查会破坏一些依赖 SSH 协议的自动化任务,就需要一种手段能够绕过 SSH 的公钥检查。

    首先看看什么是 SSH 公钥检查

    SSH 连接远程主机时,会检查主机的公钥。如果是第一次该主机,会显示该主机的公钥摘要,提示用户是否信任该主机:

    The authenticity of host '192.168.0.110 (192.168.0.110)' can't be established.
    RSA key fingerprint is a3:ca:ad:95:a1:45:d2:57:3a:e9:e7:75:a8:4c:1f:9f.
    Are you sure you want to continue connecting (yes/no)?

    当选择接受,就会将该主机的公钥追加到文件 ~/.ssh/known_hosts 中。当再次连接该主机时,就不会再提示该问题了。

    如果因为某种原因(服务器系统重装,服务器间IP地址交换,DHCP,虚拟机重建,中间人劫持),该IP地址的公钥改变了,当使用 SSH 连接的时候,会报错

    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 the RSA host key has just been changed.
    The fingerprint for the RSA key sent by the remote host is
    e9:0c:36:89:7f:3c:07:71:09:5a:9f:28:8c:44:e9:05.
    Please contact your system administrator.
    Add correct host key in /home/quanzhen/.ssh/known_hosts to get rid of this message.
    Offending key in /home/quanzhen/.ssh/known_hosts:81
    RSA host key for 192.168.0.110 has changed and you have requested strict checking.
    Host key verification failed.

    上面的警告信息说的是:

    • 服务器公钥已经改变,新的公钥的摘要是:e9:0c:36:89:7f:3c:07:71:09:5a:9f:28:8c:44:e9:05.
    • 该服务器原来的公钥记录在文件 ~/.ssh/known_hosts 中第 81 行。

    如果确认不是中间人劫持,需要连接到该服务器,怎么办呢?最简单的就是用 vi 打开 ~/.ssh/known_hosts 文件,定位到 81 行,将该行删除。之后就可以使用 ssh 连接了。

    如何让连接新主机时,不进行公钥确认?

    在首次连接服务器时,会弹出公钥确认的提示。这会导致某些自动化任务,由于初次连接服务器而导致自动化任务中断。或者由于  ~/.ssh/known_hosts 文件内容清空,

    导致自动化任务中断。 SSH 客户端的 StrictHostKeyChecking 配置指令,可以实现当第一次连接服务器时,自动接受新的公钥。只需要修改 /etc/ssh/ssh_config 文件,包含下列语句:

    加上这句

    StrictHostKeyChecking no

    或者在 ssh 命令行中用 -o 参数

    $ ssh  -o StrictHostKeyChecking=no 192.168.0.110
  • 相关阅读:
    FAQ: c++ 函数名后添加 const void function1(int &id) const
    FAQ: C++中定义类的对象:用new和不用new有何区别?
    How to create a project with existing folder of files in Visual Studio?
    How to export a template in Visual Studio?
    t4 multiple output sample
    fastjson1.2.48以下版本存在重大漏洞
    一秒完成springboot与logback配置
    统计greenplum_postgresql数据占用存储情况
    上传文件不落地转Base64字符串
    三个标签完成springboot定时任务配置
  • 原文地址:https://www.cnblogs.com/mingerlcm/p/7850233.html
Copyright © 2011-2022 走看看