1

Unable to login to EC2 ubuntu server due to permission issue.

Issue: My EC2 ubuntu server has (root & ubuntu) user and I use to login to ubuntu using ssh. By mistake I have changed the ownership of Ubuntu home directory to root and also revoked all permission from the directory for other user. So user (Ubuntu) home directory has only RWX permission for root and no one else. Now I am not able to login using SSH to ubuntu. I provided .pem file but this time I am getting password prompt irrespective of .pem file. Seems I messed up.

What I tried:

  1. Tried to login to root using ssh (Didn't allowed)
  2. Tried to login to ubuntu using ssh (Asking password because the permission issue I believe)
  3. Tried hacking in. Was running Wordpress so I put shell over server using Admin. I got reverse shell but unable to do privilege escalation to get root.

I will really appreciate if you can help me to get in my server/reset password/way to get in from AWS Dashboard/or any way.

0

Woops!

This sort of thing happens but it's a good lesson to be more careful with your access. If you've completely lost access then the options open to you will almost certainly involve shutting down the VM... You can't recover from this with 100% uptime.

If this was a local PC you could pop the hard drive out put it in another machine and reset the password from the other machine. Even though this is a virtual machine, the principle is similar. There's a solution to a similar problem here: https://stackoverflow.com/a/11776183/453851

The basic principle is that EC2 virtual machine us "volumes" as hard drives. Through the AWS console you you can:

  • shut down your virtual machine
  • detach the volume
  • create a new brand new virtual machine (with it's own volume)
  • boot the new VM
  • attach the old volume to the new VM (as a second volume)

Then log into the new VM and:

  • mount the old volume (to /mnt/)
  • chroot into the mounted file system (chroot /mnt/ /bin/bash). This will give you a command line that behaves as if it's running inside your old VM.
  • Change any password you want with passwd
  • shutdown

Finally back in the AWS console:

  • detach the old volume
  • reattach it to the old VM
  • boot the old vm
  • delete completely the new VM (BE CAREFUL TO DELETE THE RIGHT ONE)
2
  • This worked! Thanks man. You are a saviour. – Aman Sinha Sep 11 '20 at 19:49
  • @AmanSinha you're welcome – Philip Couling Sep 11 '20 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.