I accidentally moved /etc/sudoers to Documents. I need to move it back to /etc, but I can't since I need to be sudo to move files...

sudo mv Documents/sudoers /etc

sudo: unable to stat /etc/sudoers: No such file or directory
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
  • 2
    Do you have physical access to the machine? Is there a keyboard & screen attached to it? Can you boot into single user mode? – terdon Dec 6 '18 at 14:35
  • I'm using raspberry pi with sd card – Light Yugen Dec 6 '18 at 14:47
  • That doesn't answer any of the three questions I asked :) Do you have physical access to the machine? Is there a keyboard & screen attached to it? Can you boot into single user mode? – terdon Dec 6 '18 at 14:49
  • Sorry i'm new to linux, i'm using Putty for an ssh connection so yes i have keyboard and terminal, it doesn't have what you describe as single user mode – Light Yugen Dec 6 '18 at 14:51
  • 1
    @roaima I think the code you see is actually the user's failed attempt at restoring the file. – hymie Dec 6 '18 at 17:58

UPDATE 2 - if you are using raspberry pi:

Power down and pull the SD card out from your Pi and put it into your computer.

Open the file cmdline.txt and add init=/bin/sh to the end or for newer versions: systemd.unit=emergency.target. (UPDATE 2) . This will cause the machine to boot to single user mode.

Put the SD card back in the Pi and boot.

When the prompt comes up, type su to log in as root (no password needed).

mv sudoers-newname sudoers

Shut the machine down, then pull the card out again and put the cmdline.txt file back the way it was by removing the init=/bin/sh bit or for newer versions: systemd.unit=emergency.target. (UPDATE 2)

(Text adapted for sudoers deletion from here: http://mapledyne.com/ideas/2015/8/4/reset-lost-admin-password-for-raspberry-pi)


If you have root password just issue "su" but if you don't have root password, use a live cd, dvd or pendrive to just move the file back again.

For using su just:

Password: Type root password 

Via the Live-CD open the terminal and:

$ sudo fdisk -l (to get a list of partitions)

You will see the partition of your linux installation, as something like:

/dev/sda1   *                 2048 1936918527 1936916480  923,6G 83 Linux

So if in your case it is /dev/sda1 too, just

sudo -i
mkdir /mnt/sda1
mount /dev/sda1 /mnt/sda1
mv /mnt/sda1/etc/sudoers-newname /mnt/sda1/etc/sudoers 
cd /
umount /mnt/sda1 

If you have your linux installed in multiple partitions, just try mounting one by one until you find the correct one or the one that have the etc files.

That is it. Reboot.

  • i'm using a raspberry pi with sd card, how can i fix that? – Light Yugen Dec 6 '18 at 14:47
  • A minute please. – Luciano Andress Martini Dec 6 '18 at 14:48
  • @LightYugen you should be able to boot from the same SD card you originally used to install the OS. If not, see the question I linked to in my comment under your question. When you get to grub, press e and edit as described in the "single user mode" section. – terdon Dec 6 '18 at 14:48
  • See my edit on the answer. – Luciano Andress Martini Dec 6 '18 at 14:51
  • snag.gy/XzlQcE.jpg did i put it correctly? when i boot it still asks user and password – Light Yugen Dec 6 '18 at 14:59

Booting into single user mode to move the file back to where it belongs is a solution to this problem, and the easiest for a regular PC.

In this case however, the file system is on a SD card. You just need a card reader, that you also need if you want to modify the boot options, and use that to attach the SD card to a regular PC running Linux. If you don't already have a Linux on a PC, get any Linux live CD. Then mount the file system on the card and move the file to the correct place.

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.