How to Recover SSh Access to Amazon EC2 Instance After UFW firewall Activation But Forgot to Allow SSH

ufw is very good tool. But if you forget to turn on ssh then you would not able to log in to your server. But you forget to enable the ssh in ec2 instance then you have a way to recover it.

  • Stop your instance
  • Attach your EBS volume to another instance. if you don’t have one, create a instance.
  • Create a folder
  • mkdir  recover

    Check if the EBS attached.

    sudo fdisk -l

    If you see /dev/xvdf then EBS successfully attached.

  • Mount your EBS volume in to recover folder
  • mount /dev/xvdf recover
  • Edit recover/etc/ufw/ufw.conf and change enabled=yes to enabled=no
  • Umount the EBS
  • umount -d /dev/xvdf
  • Detach from the temp instance
  • Reattach to the original instance. But remember to name it /dev/sda1
  • Restart the instance
  • Login to server and allow ssh
  • ufw allow ssh

There you have it. Nice and simple

About Zakir Hyder

This entry was written by .

04. October 2014 by Zakir Hyder
Categories: Linux, Ubuntu | Tags: , , , , , , | Comments