cloudpackエバンジェリストの吉田真吾@yoshidashingo)です。

Macを使ってオートヒーリング状態のEC2(Auto Scaling Groupでインスタンス数1,Desired Capacity1,Min1,Max1)にSSH接続しており、何かのきっかけでインスタンスが破棄され復旧(オートヒーリング)した場合、新しいインスタンスのPublic DNSが、破棄されたインスタンスのそれと同一の場合があります(毎回そうとは限らないかもしれないです)

よって再度接続しようとするとMacのターミナル上に以下のような警告が出ます。

$ ssh -i ***.pem ec2-user@***.compute.amazonaws.com
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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
***.
Please contact your system administrator.
Add correct host key in /Users/***/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/***/.ssh/known_hosts:[行数]
RSA host key for ***.ap-northeast-1.compute.amazonaws.com has changed and you have requested strict checking.
Host key verification failed.

上記の警告のとおり、手元のknown_hostsのホストに記録しているRSAキーが合致しないセキュリティ警告により接続が中止されてるので、[行数]のとこの該当行をいったん削除して接続すればよいです。

$ ssh -i ***.pem ec2-user@***.compute.amazonaws.com
The authenticity of host '***.compute.amazonaws.com (***)' can't be established.
RSA key fingerprint is ***.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '***.compute.amazonaws.com,***' (RSA) to the list of known hosts.

__| __|_ )
_| ( / Amazon Linux AMI
___|___|___|

https://aws.amazon.com/amazon-linux-ami/2013.09-release-notes/

接続できて、再度known_hostsに登録されます。

AWSと直接関係ない小ネタでした。

 

2014.3.6 追記

吉川さん(@yoshikaw)からこんなアドバイスいただきました、ありがとうございます!^^

削除は ssh-keygen -R hostname がいいかなと思ってみたり。》EC2インスタンスがオートヒーリングされたらsshできなくなったとき(Public DNSが同一だった編) - yoshidashingoの日記 http://t.co/4bL0rgSRBN

— Kazuhiro YOSHIKAWA (@yoshikaw) 2014, 3月 6


こちらの記事はなかの人(yoshidashingo)監修のもと掲載しています。
元記事は、こちら