Anh Thang Bui

29 Jun 2018 ~ 1 min read

Disable firewall in EC2 instance from AWS Console


I have locked myself out of SSH with UFW in EC2 AWS. Then, I can't reconnect.

I found this script and it works with below steps:

  • Stop your problem instance
  • Paste this script in Instance Settings > View/Change 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, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
ufw disable
iptables -L
iptables -F
--//
  • Start your instance and now you should be able to SSH

Anh Thang Bui

Hi, I'm Thang.
I'm a software engineer from Hanoi, Vietnam. You can follow me on Twitter, see some of my work on GitHub, or read more about me on my website.