How to rename sudoers back to its original naming? [duplicate]

Today I made a big mistake, I run the command

mv /etc/sudoers{,.bak}

on my ubuntu machine and now sudoers file is missing

This is the message given in terminal wherever I use sudo

sudo: unable to stat /etc/sudoers: No such file or directory
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

How to make that backup file again back to normal and get back sudo?


I think the fastest way to fix this would be to get a root shell from the recovery mode and to move the original /etc/sudoers back in place:

  1. Hold LSHIFT (or ESC if LSHIFT doesn't work) at power-on to boot into grub;
  2. Select the default kernel's recovery mode (e.g. Ubuntu, with Linux 3.19.0-15-generic (recovery mode)) and hit Enter;
  3. Select root - Drop to root shell prompt and hit Enter;
  4. Run mount -o rw,remount /;
  5. Run mv /etc/sudoers.bak /etc/sudoers;
  6. Run reboot;

Since Ubuntu also has pkexec installed, and Polkit configuration is independent of sudoers:

pkexec mv /etc/sudoers{.bak,}

Oh I've done this one before. :) oops...

  1. Reboot using a LIVE CD (The one you installed Ubuntu with)

  2. Choose the "Try Ubuntu" option NOT the "Install Ubuntu" option.

    Once you are to the desktop just mount your main HDD (should show at the bottom left as a hard drive)

  3. Launch the file manager and navigate to the /etc/ folder on that newly mounted hard drive.

  4. Rename the sudoers.bak file to sudoers.

Reboot and you should be good to go. Let me know if that helps.