I have an Ubuntu 16.04 AWS instance that I accidentally locked myself out of by enabling UFW without allowing port 22 for SSH. I've created a new instance and mounted the volume of the affected instance to it.
Now I have access to the file system of the affected instance, how do I stop UFW from running on startup so that I can access the instance again through SSH? Alternatively, how do I allow access to port 22 for SSH through config files?
I've looked around online and my file structure doesn't seem to match what other people are using. In /media/myDrive/lib/ufw
I don't have user.rules
or user6.rules
; these are in /etc/ufw/
. I've edited the user*.rules
files as below to allow access, but when I rebooted the server, I still couldn't access it via SSH.
#user.rules
-A ufw-user-input -p tcp --dport 22 -j ACCEPT
-A ufw-user-input -p udp --dport 22 -j ACCEPT
#user6.rules
-A ufw6-user-input -p tcp --dport 22 -j ACCEPT
-A ufw6-user-input -p udp --dport 22 -j ACCEPT
Referenced from this SO question: Can't ssh into AWS EC2 after enabling firewall
-I
nsert to the beginning of the chain instead of-A
ppend to the end. Also, probably (sorry currently I do not have UFW installed), the defaultINPUT
chain will be read before the UFW's one, so you can try with some rules as:-I INPUT ...
...and the last one you don't need to allow UDP on the SSH port. – pa4080 Jul 26 '19 at 13:40