Fix: ssh host key verification failed

In SSH protocol, a host key is a cryptographic key that is utilized to authenticate the system. It enables a connection for communication between the host and server. While establishing a connection, an error “ssh host key verification failed” might occur.

This post will demonstrate all the possible reasons and solutions to resolve the above-stated error. The content served in this post is as follows:

Let’s start this guide.

Reason: Incorrect Host Key

 The verification of host key error may arise due to the change of remote server keys stored in the “know_hosts” configuration file. During the server rebuild, the host key is changed. Therefore, ssh does not recognize the new keys.

Let’s resolve this error.

Solution 1: Delete the Host Key

As the error is generated because the key is stored at the 3rd location in our case. The first solution is that you need to delete it from the “known_hosts” file. To do so, first access the “Known_hosts” file using the nano editor:

$ nano .ssh/known_hosts

Delete the “third” host key (as in our case, it may be different in your case) that has generated the particular error in the “known_hosts” file via “Nano Editor”. After that, press the “Ctrl +S” key to save the file and close the window using the “Ctrl+X” key.

Solution 2: Remove the Host Key via IP Address

Another solution can also be considered to resolve the error through the “ssh-keygen” command. This command generates the public key pair to access the remote server. It requires the IP address of the system for removing the host key:

$ ssh-keygen -R

After executing the command, the host key of the specific IP address has been successfully removed.

Verify the Removed Host Key

After removing the host key, execute the ssh command by specifying the “username” and IP(hostname) address to resolve the particular error.

Now, you can verify the remote connection is successfully established to the server without displaying any error:


In Linux, the “ssh host key verification failed” error can be fixed by deleting the host key through Nano Editor or using the “ssh-keygen” command. The error is generated during establishing the connection to the remote server because of the incorrect host key or changing the host key in the “know_hosts” configuration file. All the fixes for this error are briefly explained with practical examples.