文档

使用SSH远程连接Linux系统的ECS实例时,提示“Host key verification failed”错误怎么办?

更新时间:

本文介绍使用SSH远程连接Linux系统的ECS实例时,提示“Host key verification failed”的错误原因和解决方案。

问题现象

  • 本地客户端为Linux环境或macOS环境,使用SSH方式无法正常连接Linux系统的ECS实例时,提示如下错误信息。

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @ 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 the RSA host key has just been changed.
    The fingerprint for the RSA key sent by the remote host is
    ae:6e:68:4c:97:a6:91:81:11:38:8d:64:ff:92:13:50.
    Please contact your system administrator.
    Add correct host key in /root/.ssh/known_hosts to get rid of this message.
    Offending key in /root/.ssh/known_hosts:70
    RSA host key for x.x.x.x has changed and you have requested strict checking.
    Host key verification failed.
  • 本地客户端为Windows环境,使用常见的SSH客户端(如Putty或MobaXterm)连接Linux系统的ECS实例时,提示类似“The host key does not match the one Putty has cached for this server”或“remote server identification has changed”错误信息。

    windowsmoba

问题原因

该ECS实例可能进行过重装系统、账户信息变更等操作,导致ECS实例SSH公钥变更,造成本地客户端保存的公钥指纹与服务器端不一致,出现该提示信息。

解决方案

您可以根据本地客户端环境不同,选择合适的方案。

本地客户端为Windows环境

本文以SSH客户端Putty和MobaXterm进行介绍,不同SSH客户端操作有所差异,请根据实际的客户端进行操作。

客户端为Putty时,单击Accept,Putty会自动更新密钥指纹信息,即可成功登录实例。

Putty

客户端为MobaXterm时,单击Accept the new server hostkey and carry on connecting,MobaXterm会自动更新密钥指纹信息,即可成功登录实例。

MobaXterm

本地客户端为Linux或macOS环境

  1. 在本地客户端中,执行如下命令,进入对应账号的known_hosts文件。

    vim ~/.ssh/known_hosts
  2. i键进入编辑模式。

  3. 删除ECS实例IP对应的条目,如下图所示。

    known_hosts
  4. Esc键,输入:wq保存并退出。

  5. 重新连接Linux实例,确保可以正常连接。

  • 本页导读 (1)
文档反馈