简体   繁体   English

启用防火墙后无法进入AWS EC2

[英]Can't ssh into AWS EC2 after enabling firewall

After enabling the firewall with 'sudo ufw enable' I can no longer ssh into my ec2 instance. 使用'sudo ufw enable'启用防火墙后,我再也无法进入我的ec2实例。 Any way to recover from this? 有什么方法可以从中恢复? I'm guessing I should have done something like 'sudo ufw allow ssh' but didn't do that before exiting the session. 我猜我应该做的事情就像'sudo ufw allow ssh',但在退出会议之前没有这样做。 Also, if I had done that, would I be able to ssh in after that, or is there something else I would need to do? 另外,如果我这样做了,那我可以在那之后继续ssh,还是还有其他我需要做的事情? Thanks. 谢谢。

You can recover, but the process is a bit involved. 你可以恢复,但这个过程有点牵扯。

You will need to detach the volume and reattach it to a new instance. 您需要分离卷并将其重新连接到新实例。 Mount the volume, then find and edit the configuration file to allow ssh through. 挂载卷,然后查找并编辑配置文件以允许ssh通过。

Once you are done, you can swap the volume back to the original instance. 完成后,您可以将卷交换回原始实例。

In most cases, if you are in VPC and using security groups correctly, you probably wont need a software firewall enabled. 在大多数情况下,如果您使用的是VPC并正确使用安全组,则可能不需要启用软件防火墙。 Security groups can handle most of the common firewall uses. 安全组可以处理大多数常见的防火墙用途。

Success! 成功! @datasage provided the general steps to recover. @datasage提供了恢复的一般步骤。 Here are the details of the actual files I had to change, for anyone else who might need the details. 以下是我必须更改的实际文件的详细信息,以及可能需要详细信息的任何其他人。

After creating a new instance and mounting the original OS volume as a data volume to /mnt/ufwOOPS, I made the following changes to the files in /mnt/ufwOOPS/lib/ufw, the manual equivalent to 'sudo ufw allow 22': 在创建新实例并将原始操作系统卷作为数据卷安装到/ mnt / ufwOOPS后,我对/ mnt / ufwOOPS / lib / ufw中的文件进行了以下更改,该手册相当于'sudo ufw allow 22':

Add the following 3 lines, respectively, to the ## RULES ## section of user.rules and user6.rules 分别将以下3行添加到user.rules和user6.rules的## RULES ##部分

user.rules: user.rules:

### tuple ### allow any 22 0.0.0.0/0 any 0.0.0.0/0 in
-A ufw-user-input -p tcp --dport 22 -j ACCEPT
-A ufw-user-input -p udp --dport 22 -j ACCEPT

user6.rules: user6.rules:

### tuple ### allow any 22 ::/0 any ::/0 in
-A ufw6-user-input -p tcp --dport 22 -j ACCEPT
-A ufw6-user-input -p udp --dport 22 -j ACCEPT

Thanks for the tip @datasage! 谢谢你的提示@datasage!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM