thumb

When attempting to connect using SSH, the connection may be automatically rejected with the following error:

Host key verification failed

After rebuilding a web-server, I tried to login into it via SSH and have received the following error:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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
NN:NN:NN:NN:NN:NN:NN:NN:NN:NN:NN:NN:NN:NN:NN:NN.
Please contact your system administrator.
Add correct host key in /Users/Arthur/.ssh/known_hosts to get rid of this message.
Offending key in /Users/Arthur/.ssh/known_hosts:8
RSA host key for [192.168.2.2]:22 has changed and you have requested strict checking.
Host key verification failed.

“Host key verification failed” means that the host key of the remote host was changed since you ssh to it in last time and so the system does not allow access for security purposes.

So you need to change the host key in the known_hosts file. But no need to delete the known_hosts file, for example, by using the following command:

rm -f /home/user/.ssh/known_hosts

The message already told you what to do. To correct it, take a look at the last integer of the line that says “Offending ECDSA key,” because this integer is actually the line number inside your known_hosts file that’s throwing the error. Simply type the following command:

sed -i '8d' ~/.ssh/known_hosts

Where 8d is the line number, so if your line number another then you need to use another number, for example 2d.

Or you can manual edit the known_hosts file. For this you need to open the known_hosts file and manual delete the line that’s throwing the error.

sudo nano .ssh/known_hosts

If you are having trouble fixing this problem with the instructions above, but are being able to solve this problem with any another method please describe it in the comment section below. Thanks!

If this article has helped you solve the problem then please leave a comment :smiley:

Thanks for reading!