If you are using a Redhat 6.4 AMI EC2 instance on Amazon Webservices and after a reboot you can no longer connect to SSH, this might help you. There appears to be a bug in /etc/rc.local
that tries to add the same lines over and over again to /etc/ssh/sshd_config
. Here is what the problem looks like in /etc/rc.local
:
cat <<EOL >> /etc/ssh/sshd_config UseDNS no PermitRootLogin without-password
Everytime the machines startup it is going to append to the file and eventually SSH will stop coming up correctly. You may want to delete those lines or at least modify them to do something that you want them to do.
Also before you reboot take a look at /etc/ssh/sshd_config
and make sure it looks right. You may need to delete some of the extra entries from the end. You can test it by doing a:
sudo service sshd restart
If the sshd_config
is bad, this will fail to restart sshd, but it should still leave you connected so you can change the config and try restarting it again.
If your machine is running but you can’t connect to it, you can disconnect the the volume, mount it on another EC2 instance, change those files and then put it back on the original instance and start it back up.
Thanks Mark, this saved my bacon today!
Glad it was useful.
This issue was driving me nuts! So thank you very much for explaining the cause – and the fix.