Sudo doesn't work: "/etc/sudoers is owned by uid 1000, should be 0"
When I type a sudo command into the terminal it shows the following error:
sudo: /etc/sudoers is owned by uid 1000, should be 0
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
How do I fix this?
Solution 1:
Change the owner back to root:
pkexec chown root:root /etc/sudoers /etc/sudoers.d -R
Or use the visudo
command to ensure general correctness of the files:
pkexec visudo
Solution 2:
Another option, in the case that one doesn't have the password for root
or ubuntu
users. I've fat-fingered ownership (more times than I want to admit) and ending up doing this:
sudo chown -R owner:group /
instead of this:
sudo chown -R owner:group .
This has almost always been in the context of a Vagrant-managed VirtualBox VM running Ubuntu headless, so YMMV. I'd never had a good fix until now, but this seems to do the trick easyishly.
Repair
- Create or edit /etc/rc.local
- NOTE Do this as vagrant user without trying to set permissions to root.
- For this task, /etc/rc.local should look like this:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
chown -R root:root /etc/sudoers.d
chown root:root /etc/sudoers
chmod 440 /etc/sudoers
exit 0
- Disconnect from SSH
- Open VirtualBox Manager
- Right-click VM in question
- Select 'Close'=>'ACPI Shutdown'
- Start the VM from the VirtualBox Manager by right-clicking the VM entry then selecting 'Start'=>'Normal Start'
- SSH into VM
- Use your now-restored sudo set permissions for children of / back to root:root
After the fix is in place the commands in /etc/rc.local can be removed.