运行 EC2 实例突然拒绝 SSH 连接 [英] Running EC2 instance suddenly refuses SSH connection

查看:49
本文介绍了运行 EC2 实例突然拒绝 SSH 连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前我已经设置了 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 存储连接并配置到新实例.我花了几个小时……现在又发生了.上一个我安装了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出错,应该是fstab成功后启动sshd.但事实并非如此,因此 sshd 不会启动,这就是它拒绝连接的原因.解决方案是创建一个临时实例,从原始实例安装根 EBS,然后从 fstab 中注释掉内容,瞧,它让我再次连接.对于未来,我只是停止使用 fstab 并创建了一堆 shell 命令来将 EBS 卷挂载到目录中,并将它们添加到 /etc/init.d/ebs-init-mount 文件,然后运行 ​​update-rc.d ebs-init-mount defaults 以初始化文件,我不再遇到锁定 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.

更新 4/23/2015

亚马逊团队创建了一个类似问题的视频教程,并展示了如何使用这种方法进行调试: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

这篇关于运行 EC2 实例突然拒绝 SSH 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆