Its a really common cause of Ubuntu users not being able to ssh into there instances and thats ufw. There is a really easy fix though, and thats using userdata.

1- Stop your instance.
2- In the console, select your instance, go to Actions -> Instance Settings -> View/Change User Data

Copy and paste the following userdata:

 

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
–//

 

Once added, restart the instance and ssh should work. The userdata disables ufw if enabled and also flushes any iptable rules blocking ssh access.

 

I hope this helps.

2 thoughts on “Accidentally enabled UFW on your Ubuntu instance and cant SSH as a result?”

Leave a Reply

Your email address will not be published. Required fields are marked *