α
Published on

Locked myself out of SSH port Ubuntu AWS server using ufw

134 words1 min read
Authors

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.