タケユー・ウェブ日報

Ruby on Rails や Flutter といったWeb・モバイルアプリ技術を武器にお客様のビジネス立ち上げを支援する、タケユー・ウェブ株式会社の技術ブログです。

EC2でRHEL6.4のAMIから起動したインスタンスに二度とSSH接続できなくなる恐怖のバグ

ネットワークエラー.png

さんざんはまったのでメモ。

  1. RHEL6.4のAMIからインスタンスを起動
  2. 再起動
  3. sshdの起動に失敗し接続が不可能になる

何時間か浪費した後、イメージ側のバグだったことが判明orz

EC2 instance launched from AMI not reachable(ssh) after start/stop or reboot - stackoverflow

When we launch an instance from an AMI. At first the instance is accessible(ssh). Once we stop/start the instance or reboot it the machine becomes inaccessible via ssh,we can ping it though. We see below error in System log. AMI ID used - ami-72dc9220 Instance - i-0896a15f -

まさにこれです。

Was able to fix this. This is due to a bug from REDHAT for 6.4 rhel instanceshttps://bugzilla.redhat.com/show_bug.cgi?id=956531. After launching the machine from an AMI. Connect to the machine and switch to root user and make below changes to /etc/rc.d/rc.local file ...

Remove the following three lines and save the file:

cat <> /etc/ssh/sshd_config UseDNS no PermitRootLogin without-password ../ One should also remove garbage entries from /etc/ssh/sshd_config file .. The machine once rebooted after these changes works fine.

Thanks Ashwani

バ、バグ・・・

ということで、RHEL6.4のインスタンスを起動したら、

[root@host ~]# vi /etc/rc.d/rc.local

で、以下の3行を削除

cat <<EOL >> /etc/ssh/sshd_config
UseDNS no
PermitRootLogin without-password

また、/etc/ssh/sshd_configにゴミが書き出されてたら修正

UseDNS no
PermitRootLogin without-passwordUseDNS no
PermitRootLogin without-password

↓このままだと再起動後sshd_configのエラーでsshdが起動しない・・・修正

UseDNS no
PermitRootLogin without-password

ここまでできたら再起動して、再びインスタンスに接続できることを確認。