Locked myself out of SSH port Ubuntu AWS server using ufw

Currently, I locked myself out of my VPS (Amazon EC2) after configuring ufw firewall. Here are what I’ve done to disable ufw and take back the control of my VPS.

  1. Stop your problem instance
  2. 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
--//
  1. Start your instance and now you should be able to SSH.
  2. Source: https://anhthang.org/2018/06/29-disable-firewall-in-ec2-instance-from-aws-console

Đăng ký để nhận các bài viết mới nhất.