Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enable firewall port 22 on ec2 server after disable it

Step error: 1. sudo ufw enable 2. Command may disrupt existing ssh connections. Proceed with operation (y|n)? y 3. exit Before ssh again and can not access. On Security Group, port 22 is opening But firewall disable port 22. How to access server again?

like image 634
thanks Avatar asked Aug 11 '16 04:08

thanks


1 Answers

You could use the following Simplest way (user-data) to turn off the ufw.

  1. Stop the instance
  2. In Instance Settings, View/Change User Data
  3. Copy and Set the below user data as plain text and save
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, once]

--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"

#!/bin/bash
sudo ufw disable
--//
  1. Start the instance

You will be able to SSH into your server now as ufw is disabled. You might want to stop the instance and remove user data and start it again.

like image 84
Thomas Avatar answered Oct 04 '22 20:10

Thomas