ssh,

Fix 'host key has just been changed'

Mar 25, 2023 · 1 min read · Post a comment

Let’s see how to resolve the error below while trying to establish an SSH connection:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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 a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:tksCsDhcuhkiVzc0u9e8BujQXVUpKZIDTMczCvj3tD.
Please contact your system administrator.
Add correct host key in /home/home.user/.ssh/known_hosts to get rid of this message.
Offending RSA key in /home/home.user/.ssh/known_hosts:60
Host key for github.com has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.

Prerequisites

  • ssh
  • sudo privileges

Solution

  • The error message typically indicates that there is an issue with the SSH connection between your local machine and the remote host. Here I will show you how to fix it quickly.

  • To resolve it, open the /home/home.user/.ssh/known_hosts file, in my case line 60. You can find that in the error output above.
    nano +60 /home/home.user/.ssh/known_hosts
    
  • Remove that line and save the file.

  • Try to establish an SSH connection again. It will ask you for a new fingerprint. Type yes and the issue will be fixed.

Conclusion

Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.