Fix for WARNING REMOTE HOST IDENTIFICATION HAS CHANGED!

In this short article we will go over the fix for this warning message "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!" Here is the output for this type of warning:

[root@aodba]# ssh -i /home/ec2-user/KEY.pam ec2-user@11.111.11.222
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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
3e:02:5b:61:b1:f1:1a:72:ed:89:88:c6:6a:79:c9:80.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending RSA key in /root/.ssh/known_hosts:1
RSA host key for 11.111.11.222 has changed and you have requested strict checking.
Host key verification failed.
 Why do you get this error ?  This is common when you change the name of your server or like in my case when you recover a server from a faliure and give it the same ip address as in the past. What is the fix for this warning ?  The fix is quite simple. You just need to remove the line from you ../known_hosts file that points to the ip/host you are trying to connect to. 1 - You can do by editing your known_hosts using and editor. 2 - Use ssh-keygen command with the -R option.
  • the -R option will require the host name or the ip address as input and it will remove the specific line from your ../known_hosts.
[root@aodba]# ssh-keygen -R 11.111.11.222
/root/.ssh/known_hosts updated.
Original contents retained as /root/.ssh/known_hosts.old
Next you just need to login again and the new key will be added to the ../known_hosts file.
[root@aodba]# ssh -i /home/ec2-user/NAT.pam [email protected]
The authenticity of host '11.111.11.222 (11.111.11.222)' can't be established.
RSA key fingerprint is 3e:02:5b:61:b1:f1:1a:72:ed:89:88:c6:6a:79:c9:80.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '11.111.11.222' (RSA) to the list of known hosts.
And we are done !