enable firewall port 22 on ec2 server after disable it

筅森魡賤 提交于 2019-12-07 17:35:47

问题


Step error: 1. sudo ufw enable 2. Command may disrupt existing ssh connections. Proceed with operation (y|n)? y 3. exit Before ssh again and can not access. On Security Group, port 22 is opening But firewall disable port 22. How to access server again?


回答1:


You could use the following simplest way (user-data) to turn off the ufw then access the instance and edit your firewall.

  1. stop the instance
  2. Edit the user data to disable the ufw once and let you access the instance
  3. start the instance

Following is the user data:

Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0

--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"

#cloud-config
cloud_final_modules:
- [scripts-user, once]

--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"

#!/bin/bash
sudo ufw disable
--//



回答2:


At this point, there is nothing you can do to get back into the machine. It seems (from your comments) that ufw automatically starts and you have not added a rule to it to allow SSH traffic.

What you can do to recover data is

  • shut down the EC2 instance,
  • detach the EBS volume,
  • launch a different EC2 instance,
  • log into it,
  • mount the EBS volume and
  • copy the data to the new instance


来源:https://stackoverflow.com/questions/38887117/enable-firewall-port-22-on-ec2-server-after-disable-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!