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
 1Content-Type: multipart/mixed; boundary="//"
 2MIME-Version: 1.0
 4Content-Type: text/cloud-config; charset="us-ascii"
 5MIME-Version: 1.0
 6Content-Transfer-Encoding: 7bit
 7Content-Disposition: attachment; filename="cloud-config.txt"
10- [scripts-user, always]
12Content-Type: text/x-shellscript; charset="us-ascii"
13MIME-Version: 1.0
14Content-Transfer-Encoding: 7bit
15Content-Disposition: attachment; filename="userdata.txt"
17ufw disable
18iptables -L
19iptables -F
  1. Start your instance and now you should be able to SSH.

Related Posts

Airflow, MLflow or Kubeflow for MLOps?

Machine learning is now focusing more on the data (data-centric AI), and MLOps is obviously the way to bring ML projects into production.

Read more

With Daisykit – Everyone can build AI projects!

Imagine you are a software engineer or a DIY hobbyist with great ideas to build AI-powered projects. However, it will be such difficulty when you know very little or nothing about AI.

Read more

Install ROS 2 on Raspberry Pi 4 (SD card image available)

ROS2 is an excellent framework for robotics applications. You can go further and embed a completed ROS 2 application stack in a small robot base with a Raspberry Pi computer.

Read more