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?
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?
Change the owner back to root:
Or use the
visudo
command to ensure general correctness of the files:Another option, in the case that one doesn't have the password for
root
orubuntu
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
After the fix is in place the commands in /etc/rc.local can be removed.
to recover from
The last of which results in the "sudo: /etc/sudoers is owned by uid 1000, should be 0", etc. errors. I tried to su - sudo which I've seen suggested but I don't think the root password was ever set so that did not work.¹
To fix this issue, I rebooted, dropped into a root shell and²
Rebooted, voila.
NB: The pkexec commands suggested did not work for me while I was initially trying to fix the problem. After it was fixed via the recovery mode root shell, I subsequently tried it and a GUI window popped up asking for my password and it did work so YMMV.
¹ After fixing the problem, I repeated the steps and was able to recover with²
² The list of commands Rohlt suggests were unnecessary in my case but they might apply in other cases.
if you have set and have the root password, first run the following command
it will ask for the root password and then run following commands one by one