Ubuntu – Root Locked Out of Ubuntu 12.04

SecuritysshsudoUbuntu

I may have just locked root out of my server, and am looking for help. I have a VPS web server that has been running 10.04 for the past couple of years. For security, I had disabled root login and password authentication. This has been perfect until now, my user has sudo permissions so I've never had difficulty with this arrangement.

I'm doing some work on the box today and a package I need won't run on Lucid, so I upgraded to 12.04. Unfortunately, in the process of upgrading the sudoers file was overwritten (it did ask me first, but I wasn't paying attention and allowed it).

I still have SSH access to the box, but I no longer have sudo permissions. Am I hosed, or is there a way to recover?

Best Answer

Use the Lish console provided by Linode to obtain out-of-band console access and reboot the VM into single-user mode to reset the root password (and/or fix your sudoers file).

To do this you need to stop GRUB before the timeout expires and follow this procedure:

  • Press e to edit the kernel boot parameters.
  • Append a space, and the number 1 to the kernel line.
  • Press Esc to apply your change.
  • Press b to boot using the modified settings.

(Note: these changes are not permanent, so you will not have to undo them later. They apply only to this boot.)

You will be dropped into a single user shell with the root filesystem mounted read-only. You'll want to remount it re-write with:

mount -o remount,rw /

Then you can make the changes you like to the system and reboot.

Good luck!