Question

I had a nice and stable Ubuntu 12.04 Amazon Machine Image (AMI) and I was logging into my Amazon EC2 instance by using pem file (ssh -i dev.pem ubuntu@<instance_name>.compute-1.amazonaws.com). One day the permission on /ubuntu folder changed and I'm no longer able to connect to the EC2 instance, the SSH error is Permission denied (publickey).

Is there any way I can reset the permission on that folder?

Appreciate for all your help.

Was it helpful?

Solution

Loosing access to an Amazon EC2 instance is a common encounter - how to approach this situation when you don't know the reason yet is addressed in Eric Hammond's excellent summary Solving: "I can't connect to my server on Amazon EC2". However, since you already now what caused this, you can apply his respective instructions Fixing Files on the Root EBS Volume of an EC2 Instance right away.

  • Note: this only applies to instances with Amazon EBS based Root Device Storage, because only these can be stopped without loosing the root volume, so take care not to terminate your instance instead!

With that out of the way, the process boils down to:

  • start another EC2 instance
  • stop (not terminate!) the EC2 instance you can't access anymore
  • detach the EBS volume from the stopped instance
  • attach the EBS volume to the running instance
  • SSH into the running instance
  • mount the EBS volume in the running instance
  • perform whatever fixes necessary, i.e. adjust the /ubuntu permissions in your case

Please see Eric's instructions for details on how to do this from the command line; obviously you can achieve all steps up to the SSH access via the AWS Management Console as well, removing the need to install the Amazon EC2 API Tools, in case they aren't readily available already.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top