Running EC2 instance suddenly refuses SSH connection

后端 未结 9 841
小鲜肉
小鲜肉 2020-12-14 08:42

I\'ve set up the EC2 instance couple days ago and even last night I was able to SSH to it with no problems. Today morning, I can\'t ssh to it. Port 22 is already open in the

相关标签:
9条回答
  • 2020-12-14 09:20

    If your ubuntu has systemd, you can edit /lib/systemd/system/local-fs.target and comment out the last two lines:

    #OnFailure=emergency.target
    #OnFailureJobMode=replace-irreversibly
    

    I haven't tested this extensively and don't know if there are any risks or side effects involved, but so far it works like a charm. It mounts the root volume and all other volumes (except those that are misconfigured, obviously), then it continues the boot process until SSH is up, so you can connect to the instance and fix the incorrect fstab entries.

    0 讨论(0)
  • 2020-12-14 09:22

    With the help of @abhi.gupta200297, we were able to resolve it.

    The issue was the error in /etc/fstab, and sshd was supposed to be started after fstab is successful. But it wasn't, hence, the sshd wouldn't start and that's why it was refusing the connection. Solution was to create a temporary instance, mount the root EBS from the original instance, and comment out stuff from the fstab and voila, it's letting me connect again. And for the future, I just stopped using fstab and created bunch of shell commands to mount the EBS volumes to directories and added them in /etc/init.d/ebs-init-mount file and then run update-rc.d ebs-init-mount defaults to initialize the file and I'm no longer having issues with locked ssh.

    UPDATE 4/23/2015

    Amazon team created a video tutorial of similar issue and show how to debug using this method: https://www.youtube.com/watch?v=_P29ZHu_feU

    0 讨论(0)
  • 2020-12-14 09:22

    I got similar ssh locked out by detach an EBS but forgot to modify the /etc/fstab

    0 讨论(0)
提交回复
热议问题