Fix SSH WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED
Run `ssh-keygen -R hostname` to remove only the outdated key for the specific host from your known_hosts file, then reconnect and accept the new fingerprint. Alternatively, open `~/.ssh/known_hosts`, find the line matching the host, delete it manually, and save. This avoids removing all trusted hosts while resolving the mismatch error immediately.
If the fingerprint of your remote host changes you will see the following error message appear:
~ % ssh -i "mykey.pem" [email protected]
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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 ED25519 key sent by the remote host is
SHA256:S60CvpE17ri+E594StxXBQcNIrga4Nb7uX4s7BPr3dw.
Please contact your system administrator.
Add correct host key in /Users/user_id/.ssh/known_hosts to get rid of this message.
Offending ED25519 key in /Users/user_id/.ssh/known_hosts:2
Host key for my_host.af-south-1.compute.amazonaws.com has changed and you have requested strict checking.
Host key verification failed. There are many ways to fix this. The easiest of which is simply to delete your “known_hosts” file. This will mean you just need to accept new finger prints on all your SSH hosts. Yes, this is very lazy…
rm ~/.ssh/known_hosts