Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I messed around with the sudoers file without really knowing what I was doing using this link.

Assume I did everything that was in the top answer along with editing it with vim and not visudo. How do I fix this?

I'm running Xubuntu 12.04, and I didn't set a root password.

share|improve this question

1 Answer 1

up vote 12 down vote accepted

The easiest fix is to boot from a Live CD, then mount your local drive and edit or revert to the old sudoers file.

  1. Boot from a live CD

  2. Find your / partition. Open a terminal and run lsblk or sudo fdisk -l or blkid and identify your root (/) partition. For this example, I will assume it is /dev/sda1.

  3. Mount your root partition to a temporary location

    sudo mkdir /foo
    sudo mount /dev/sda /foo
    
  4. Now that the partition is mounted, check the /foo/etc directory. You probably have a file called /etc/sudoers~ which is a backup of your sudoers file. If so, this will probably solve everything:

    sudo cp /foo/etc/sudoers~ /foo/etc/sudoers
    

    If that doesn't work, just edit the file and revert your changes as best you can (or add it to your question and we can help you out with it). If you introduced lines with a syntax error, remove them or comment them out by adding # at the beginning. If you removed the line that granted you sudo powers, it was probably like this (where sudo is a group that your user is in, i.e. your username is mentioned on the line in /etc/group that begins with sudo:)

    %sudo   ALL=(ALL:ALL) ALL
    
  5. Take the CD out and reboot.

share|improve this answer
2  
Not only is this the right answer, but it's a good learning experience - since the OP sounds like a Linux newbie, this makes for a good illustration of how to recover after doing something bad to your root partition. And, fortunately, messing up /etc/sudoers is a pretty easy "something bad" to recover from. –  godlygeek Jun 20 at 11:16
    
@godlygeek: It's a good answer, but a better answer is switch to root and fix it, which, given the distributions' ridiculous user default user policy, is impossible. So terdon has provided what is, unfortunately, the best answer possible. –  mikeserv Jun 20 at 23:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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