[ssh] How to fix 'Warning: the RSA host key for 'server_name' differs from the key for the IP address 'xxx'
After creating a new EC2 instance, I edited /etc/hosts to keep the hostname the same but change only the IP address. When I ssh’d, the following warning message started appearing every time.
[ec2-user@hoge ~]$ ssh server_name
Warning: the RSA host key for 'server_name' differs from the key for the IP address '10.123.123.123'
Offending key for IP in /home/ec2-user/.ssh/known_hosts:232
Matching host key in /home/ec2-user/.ssh/known_hosts:46
Are you sure you want to continue connecting (yes/no)?
The cause is that known_hosts still contains old connection information for the host name and IP address combination, so delete line 46 of known_hosts as indicated in the message Matching host key in /home/ec2-user/.ssh/known_hosts:46.
[ec2-user@hoge ~]$ vim .ssh/known_hosts
# Delete line 46
After editing known_hosts, ssh again.
[ec2-user@hoge ~]$ ssh server_name
The authenticity of host 'server_name (10.123.123.123)' can't be established.
ECDSA key fingerprint is 6b:d3:33:ab:75:ee:50:dc:f0:0a:ca:7c:7e:bd:14:8e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'server_name' (ECDSA) to the list of known hosts.
After disconnecting and ssh’ing again, the warning message no longer appeared.
[ec2-user@hoge ~]$ ssh server_name
Last login: Thu Dec 31 00:48:26 2015 from forward_proxy1
__| __|_ )
_| ( / Amazon Linux AMI
___|\\___|___|
That’s all from the Gemba.