6

I faced this issue when I want to use sudo command :

sudo: /etc/sudoers is owned by uid 1000, should be 0
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

then I tried a solution from a similar question in order to change the owner back to the root:

$ pkexec visudo

also I tried this one

$ pkexec chown root:root /etc/sudoers /etc/sudoers.d -R

but I have faced another issue with these commands:

Error getting authority: Error initializing authority: Could not connect: No such file or directory

So is there a solution to this issue?


Full shell issue snippets:

ubuntu@LAPTOP-D4T16P7J:~$ sudo -i
sudo: /etc/sudoers is owned by uid 1000, should be 0
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
ubuntu@LAPTOP-D4T16P7J:~$ pkexec visudo
Error getting authority: Error initializing authority: Could not connect: No such file or directory
ubuntu@LAPTOP-D4T16P7J:~$ pkexec chown root:root /etc/sudoers /etc/sudoers.d -R
Error getting authority: Error initializing authority: Could not connect: No such file or directory


This is my /etc/sudoers file:

ubuntu@LAPTOP-D4T16P7J:~$ cat /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d


OS info:

  • Ubuntu WSL2.

2 Answers2

5

The answer was as follow:

  • access root user by issuing this command in windows command line (CMD):

    wsl -u root
    
  • change ownership of /etc/sudoers file to the root:

    chown root:root /etc/sudoers
    


Thanks to @Terrance for him help.

Kulfy
  • 17,696
0

I've had similar issue.

using wsl -u root resulted in error.

Open cmd, run wsl -l to get distribution name.

In my case output was Ubuntu-18.04

run wsl -d Ubuntu-18.04 -u root

You should be using root now.

run chmod 440 /etc/sudoers

temo
  • 101