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?

  • Was there not a user created in the admin group when you installed? Desktop ubuntu doesn't require editing sudoers to get sudo permission. Also, what's your VPS provider? You might be able to get tech support for this. – Random832 Oct 18 '12 at 20:45
  • I agree with @Random832. You should check with your VPS provider. They usually offer support; especially to those who are long lasting customers. But next time you shouldn't disable root login. If everything disable ssh root login. That's very common. But if you're already logged in you should be able do a su and login as root. – Flo Oct 18 '12 at 20:50
  • 1
    That's why I would always use PermitRootLogin without-password (if I didn't nevertheless use PasswordAuthentication no...). – glglgl Oct 18 '12 at 20:56
  • @Flo ubuntu isn't designed for root login. VPS providers often mess with that, but it's not how you're "supposed" to do it. – bonsaiviking Oct 18 '12 at 20:58
  • Thanks all. VPS is hosted at Linode. I've contacted support. I feel pretty stupid at the moment. My fingers are crossed. – Lenwood Oct 18 '12 at 21:03

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!

  • That should be a space followed by 1. – Michael Hampton Oct 18 '12 at 23:13
  • The Lish console saved me, I now have full access again. Thanks Kyle! – Lenwood Oct 19 '12 at 14:05

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.