Fix “host key has just been changed” error on SSH

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Hello, friends. Working with SSH is essential as a sysadmin. That’s why some errors can give you many headaches, but eventually, they have a pretty simple solution. Today, for example, you will learn how to fix “host key has just been changed” error on SSH.

Although this error can give you many headaches, it is a common error that occurs when there is a change in the host RSA key. Now, this usually occurs in operating system re-installations and a change in the server’s fingerprint happens.

The error or warning message appears to avoid possible impersonation on the server. This practice can be premeditated by many sysadmins that periodically change the identity of the server to verify that the connection is valid.

But the point is that we have to fix this error. Let’s go for it.

Fix “host key has just been changed” error on SSH

When you try to access your server via ssh with this syntax, for instance

ssh [email protected]

And you get this error

“host key has just been changed” error on SSH

It is because something has changed on the server and to avoid security leaks, access to the server is denied. This, although annoying, is an important security measure for you.

To simply fix the problem of being denied ssh access, what you need to do is to delete the previous keys you had in your known hosts file ~/.ssh/known_hosts.

Doing this manually by editing the file can be a bit cumbersome. So, the best way to do this is to simply run

ssh-keygen -R [ip-server]

For example,

ssh-keygen -R 10.11.12.13

This will delete the key, and you will be able to access the server again.

ssh [user]@[server]

And the issue is solved without any problems.

Finally, if the connection is made through a defined port besides 22, you can specify it with : to be more specific.

ssh-keygen -R 10.11.12.13:[port]

Conclusion

In this post, you can quickly fix one of the most common errors in working with SSH.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook