I changed /etc/sudoers, and now I can't run as sudo

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.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply