DEV Community 👩‍💻👨‍💻

Cover image for Restoring AWS System after messed up
Rushabh Gedam
Rushabh Gedam

Posted on

Restoring AWS System after messed up

While many of developers are focusing on RAD (Rapid Application Development), preferable to go with AWS systems.
Well, this is pretty much best solutions at ever.
But in case if you've messed up with the firewall or permissions of the filesystem, then I got something for you.
Recently I stuck in scenario where I misconfigured the Firewall & changed the OS level files User Group.
But fortunately I found a solution,
Here it is.

For a case where I set the permissions for /home/ubuntu to 777, my OS is Ubuntu 18.06

  1. Go to EC2 Instances
  2. Stop the instance with which you've played & dumped it down.
  3. Right Click on the instance & go to Edit User Data
  4. Paste the below command
bootcmd:
- cloud-init-per always fix_broken_ufw_1 sh -xc "sudo chown root:root /home >> /var/tmp/svc_$INSTANCE_ID 2>&1 || true" 
- cloud-init-per always fix_broken_ufw_1 sh -xc "sudo chmod 755 /home >> /var/tmp/svc_$INSTANCE_ID 2>&1 || true"
- cloud-init-per always fix_broken_ufw_1 sh -xc "sudo chown ubuntu:ubuntu /home/ubuntu -R >> /var/tmp/svc_$INSTANCE_ID 2>&1 || true"
- cloud-init-per always fix_broken_ufw_1 sh -xc "sudo chmod 700 /home/ubuntu /home/ubuntu/.ssh >> /var/tmp/svc_$INSTANCE_ID 2>&1 || true"
- cloud-init-per always fix_broken_ufw_1 sh -xc "sudo chmod 600 /home/ubuntu/.ssh/authorized_keys >> /var/tmp/svc_$INSTANCE_ID 2>&1 || true"
Enter fullscreen mode Exit fullscreen mode

In brief
Consider your

- cloud-init-per always fix_broken_ufw_1 sh -xc "your entire command with sudo as you do it on normal ubuntu >> /var/tmp/svc_$INSTANCE_ID 2>&1 || true"
Enter fullscreen mode Exit fullscreen mode

Just start & boom.

Top comments (0)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.