[ssh] Warning: the RSA host key for ‘server_name’ differs from the key for the IP address ‘xxx’ の解決方法
- 2015 12/31
EC2 instance を新しくした後 /etc/hosts を編集して、hostname はそのままで ip address だけ変更して ssh したら毎回下記のような警告メッセージが表示されるようになってしまいました。
[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)? |
known_hosts に host name と ip address の古い組合せの接続情報が残っているのが原因なので Matching host key in /home/ec2-user/.ssh/known_hosts:46 のメッセージに書かれているように known_hosts の 46 行目を削除しましょう。
[ec2-user@hoge ~]$ vim .ssh/known_hosts # 46 行目を削除する |
known_hosts を編集後、再び ssh します。
[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. |
その後、切断してもう1度 ssh すると Warning メッセージが表示されなりました。
[ec2-user@hoge ~]$ ssh server_name Last login: Thu Dec 31 00:48:26 2015 from forward_proxy1 __| __|_ ) _| ( / Amazon Linux AMI ___|\___|___| |
以上です。