Amazon EC2 – How to Recover Access to Ubuntu Instance Locked Out Due to /home Permissions

amazon ec2file-permissionsUbuntu

I was showing my kids some basic things about directory permissions on an EC2 ubuntu instance, and did this

$ sudo chmod 700 /home

Then demonstrated that I could no longer cd to my home directory because permission was denied.

Then I inadvertantly disconnected from the EC2 instance. Now I cannot log back in because the sshd on the ubuntu side cannot access my /home/ubuntu/.ssh/authorized_keys file. I've tried to think about workarounds, but I'm out of ideas.

I am prepared to delete and recreate the entire instance, but would much rather salvage this one if possible. Any ideas?!

Best Answer

Following Tim's suggestion:

I clicked Launch Instance to create a new instance. I just took whatever the first AMI was listed (some Amazon version of Linux) and created it with defaults, using a keypair I had already on hand.

I then clicked on Volumes and detached the EBS volume from my hosed machine. This took about 30 secs. Then I selected Attach Volume and I attached it to the new instance as /dev/sdf. Then I sshed into the new instance.

In the new instance I typed

$ sudo mkdir /caribou
$ sudo mount /dev/sdf1 /caribou
$ cd /caribou
$ sudo chmod 755 home

That repaired the /home dir permissions.

I then went back to the EC2 console, detached the EBS volume from the Amazon instance and re-attached it to my original Ubuntu instance as /dev/sda1. Then I started the old instance and logged in, with everything fixed.

Took 30 mins including time to figure out all of the above. Thanks to Tim.