Can’t access SSH after enable UFW in EC2 AWS?

May be you enabled UFW? You may be trying to enable the ufw or trying to give access to the apache server and you stuck into a disabled ssh access, Hi-Fi, I know this may be very frustrating when you are trying to install everything related to your project and this shitty thing happen to you, But no worries, I am here to get rid of that situation.

there are few steps, to get out of this problem.

1. Stop your instance

This is very simple task, you can stop instance by right click on the instance -> instance state -> stop

stop_instance

2. Go to `Instance Settings -> View/Change user Data

You must stop instance before go to this step.

3. Important Part 😛

Now paste there following snippet.

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

snippet_save

4. Now Restart you instance and get access to SSH. Now first allow port 22.

sudo ufw allow 22

Good Luck!! 😀

Spread the love
Last modified: February 27, 2020

Comments

Write a Reply or Comment

Your email address will not be published.