Rathik's dev blog

Can not Access SSH in AWS after enable UFW firewall

Black network switch with cables
Published on
/2 mins read/---

did you enable UFW on your EC2 instance for any kinds work like setup apache, ngnix , ftp or something. After that got stucked ? Its really sucks for a newbie like me sometimes when you are learning AWS.

aws can't access ec2

Follow this step carefully, Hope you will be get rid from this problem.

1. First you need to stop the AWS instance or light-sail. Give a few seconds to be stopped.

step 1

For this just right click on the instance, you will get the option like my one.

2. Again go to the right click and change user data.

step 2

After click on instace setting-> you need to edit the user data.

2. Final action

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

Copy this code and paste this user data & save it. Now please start the instance , it will work like a charm 😍 Fill Free to comment to mail me if there has still problem.

Read More