No announcement yet.

How to Fix the "Host Key Verification Failed" Error


Unconfigured Ad Widget

  • Filter
  • Time
  • Show
Clear All
new posts

  • How to Fix the "Host Key Verification Failed" Error

    Hello everyone,

    I'm currently dealing with a "Host Key Verification Failed" error and would appreciate any guidance or solutions you might have to fix this issue.

  • #2
    The "Host key verification failed" or "Remote host identification has changed" warnings appear when you attempt to connect through SSH to a remote server and show that your SSH client cannot validate the authenticity of the host you are connecting to.

    One of the most frequent causes is unrelated to an assault; it typically occurs after changing or reinstalling the OS on your VPS.

    How to Fix the "Host Key Verification Failed" Error

    Step - 1: Remove the Entry From the known_hosts File

    There are three methods to solve this error.

    Method - 1:
    The "sed" command is the first step in correcting this issue. The "sed" command is used to edit text files so that anything can be added, searched for, or removed.
    • $ sed -i '7d' ~.ssh/known_hosts
    Where "7" is the line number displayed in the above error. Your line number may differ; use the correct line number. The command will address the problem by removing the problematic line from the "known_hosts" file.

    Method - 2:
    The second method is to launch any editor and examine the "known_hosts" file:
    • $ nano .ssh/known_hosts
    Then, manually remove the problematic line and save the document.

    Method - 3:
    The known_hosts file on your local computer received a host key when you first connected to your VPS over SSH. This entry must be removed since your OS has changed or been reinstalled and rendered outdated. Perform the below command:
    • ssh-keygen -R [IP address]
    Ensure you replace your VPS's IP with [IP address]. This will erase the host key entry linked to your VPS IP and make a backup copy of the known_hosts file.

    Step - 2: Connect to the server

    Once the outdated entry has been deleted, try SSHing onto your VPS again.

    You should be able to connect and validate the host key successfully.

    After completing the steps mentioned above and still being unable to connect, you can attempt the following:
    • Check that the IP address (or hostname) you use to connect is right.
    • Check to see if your firewall is preventing the connection.
    • Restart your local device or the VPS to restore the default network settings.