This question already has an answer here:

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?

marked as duplicate by David Foerster, Pilot6, user364819, Eric Carvalho, waltinator Sep 18 '15 at 5:02

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • If you search for the name of the backup file are you able to locate it anywhere on your filesystem? – user364819 Aug 25 '15 at 13:06
  • 2
    does mv /etc/sudoers{.bak,} work? – fedorqui Aug 25 '15 at 13:06
  • @fedorqui no it says permission denied – Suraj Palwe Aug 25 '15 at 13:08
  • @ParanoidPanda yes I can locate it in my file system – Suraj Palwe Aug 25 '15 at 13:09

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;
  • 2
    Thanks for very detailed help!!!!... now my day will go all right!!! – Suraj Palwe Aug 25 '15 at 14:00
  • @SurajPalwe No problem :) – kos Aug 25 '15 at 14:01

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

pkexec mv /etc/sudoers{.bak,}
  • 2
    Ah not that a +19 on an answer like the one I gave were deserved, but to see that it's not even the best answer also feels a bit uncomfortable. @SurajPalwe I think this should be the accepted answer, it's way better than my answer. – kos Aug 26 '15 at 11:58
  • @kos thanks, but the command was correct as is. I was using brace expansion. – muru Aug 26 '15 at 12:22
  • Ah, indeed. Pardon me. – kos Aug 26 '15 at 12:40
  • +1 It never ceases to amaze me how often I find important things like this that I have never seen before! This comes under the heading of "elegant". – Joe Aug 27 '15 at 9:34

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.

  • 2
    This is fine, +1, however getting a root shell from grub should be faster / easier – kos Aug 25 '15 at 13:16
  • I'm not to familiar with how to manipulate grub but I figured if he does not know how to fix the renaming of a file he's never going to figure out how to mount his drive via shell to get access to the contents to fix the issue. – Techieman75 Aug 25 '15 at 13:26
  • That's probably right, however nevermind, I just added another answer myself (with step-by-step instructions) – kos Aug 25 '15 at 13:38
  • This is also accepted answer but I tried using @kos answer , as I didn't had CD with me right now.. Thanks for your help.. – Suraj Palwe Aug 25 '15 at 14:01

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