September 30, 2017

SSH : Remote host identification has changed

So you have recently connected to a remote Server A via ssh.

The Server A's key is then saved into a file in your local PC, typically $HOME/.ssh/known_hosts

It may looks like this :

serverA ecdsa-sha2-nistp256 AAAAE2VjZHNhLXasdasdasdmlzdHAyNTYAAAAIbm
lzddddHAyNTYAAABBBNrIVAhYMcnUasdasdsdoMv7gtf8nMHghgYzVcdddkzbDM79C
81qswhYdd8L9VX+pNjg+asdasdasdasdasdasdxgooCk=

Imagine, suddenly, the remote Server A changed their key.
As a result, the key you have in your local PC, inside known_hosts becomes invalid.

The moment you try to ssh to Server A again, you will be prompted with :

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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
a7:a8:f2:97:94:33:58:b7:9d:bc:e0:a6:6b:f7:0a:29.
Please contact your system administrator.
Add correct host key in /home/ramesh/.ssh/known_hosts to get rid of this message.
Offending key in /home/ramesh/.ssh/known_hosts: 6
Permission denied (publickey,password).
The solution is to edit the file known_hosts and remove the existing key of Server A,
using your preferred text editor i.e. vi or vim or nano or notepad

When you try to ssh to Server A again, the new key of Server A will be saved into 
your local file known_hosts.