运行EC2实例突然拒绝SSH连接实例、突然、SSH

2023-09-11 08:38:33 作者:劳娘五行缺你

我已经设置了EC2实例前几天,甚至昨晚我能够SSH到它没有问题。今天早上,我不能ssh到它。端口22是安全组已经打开,从昨晚起,我并没有改变任何东西。

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 security group and I haven't changed anything since last night.

错误:

ssh: connect to host [ip address] port 22: Connection refused

我有类似的问题,最近,我无法弄清楚,为什么它发生,所以我不得不创建一个新的实例,再设置它,并连接和配置所有EBS存储器到新的。我花了几个小时......如今它再次发生。在previous之一,我已经安装了 denyhost ,这可能阻止我,但在当前,只有的Apache2和MySQL运行。

I had similar issue recently and i couldn't figure out why it was happening, so I had to create a new instance, set it up again, and connect and configure all EBS storages to the new one. Took me couple hours... and now it's happening again. In the previous one, I've installed denyhost, which might have blocked me, but in the current one, there are only apache2, and mysql running.

目前的情况下已经运行16个小时了,所以我不认为这是因为它没有完成启动...此外,22端口是开放给所有源(0.0.0.0/0),并用TCP协议。

The current instance has been up for 16 hours now, so I don't think it's because it didn't finish booting... Also, port 22 is open to all sources (0.0.0.0/0) and is using tcp protocol.

任何想法?

感谢。

推荐答案

通过@ abhi.gupta200297的帮助下,我们能够解决这个问题。

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

这个问题是在 / etc / fstab文件的错误,并且sshd的应该在的fstab 来开始是成功的。但事实并非如此,因此,sshd的将无法启动,这就是为什么它被拒绝的连接。解决方案是创建一个临时实例,从安装原始实例的根EBS,并从的fstab ,瞧,它让我重新连接注释掉的东西。而对于未来,我只是停止使用的fstab ,创造了一堆壳的命令来安装EBS卷目录,并添加它们的/ etc / init的.D / EBS-初始化贴文件,然后运行更新-rc.d的EBS-INIT贴装默认初始化文件,我'米不再具有锁定ssh的问题。

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.

更新2015年4月23日

亚马逊的团队创建了类似的问题的视频教程,并展示如何使用这种方法进行调试:的https: //www.youtube.com/watch?v=_P29ZHu_feU

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