4

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?!

Fixee
  • 648
  • 4
  • 13

2 Answers2

7

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.

Fixee
  • 648
  • 4
  • 13
0

I'm not sure if EC2 has this option (it should), but if you haven't disabled root login completely, then open a console session on your instance through EC2 website, log in as root, restore readable permissions and you should be fine.