I'm using WSL1 and at some point I did something that means I can no longer use the 'sudo' command at all (unfortunately, I can't remember what I did or when that caused this issue but it definitely used to work – I'm very new to all this, so apologies!).
When I run anything beginning with 'sudo' I get the following errors:
sudo: /etc/sudoers is owned by uid 1000, should be 0 sudo: no valid sudoers sources found, quitting sudo: unable to initialize policy plugin
I've spent a while looking for solutions but nothing seems to work so far. E.g. I've tried using
pkexec visudo
But anything like that throws this error:
Error getting authority: Error initializing authority: Could not connect: No such file or directory
I saw another thread that suggested going into the Windows command line and entering the following:
wsl -u root
But that simply returns
User not found.
Is there any way to get back my sudo permissions or have I done something that's unsalvageable, requiring me to uninstall WSL and start again? Thanks.
Further info Thanks all for your answers. It's looking I will have to wipe WSL and start over (teaches me not to mess with things I don't understand!). @NotTheDr01ds – you asked what cat /etc/passwd, and stat /etc/passwd show. cat /etc/passwd shows the following
root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin systemd-network:x:100:102:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologin systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologin syslog:x:102:106::/home/syslog:/usr/sbin/nologin messagebus:x:103:107::/nonexistent:/usr/sbin/nologin _apt:x:104:65534::/nonexistent:/usr/sbin/nologin lxd:x:105:65534::/var/lib/lxd/:/bin/false uuidd:x:106:110::/run/uuidd:/usr/sbin/nologin dnsmasq:x:107:65534:dnsmasq,,,:/var/lib/misc:/usr/sbin/nologin landscape:x:108:112::/var/lib/landscape:/usr/sbin/nologin sshd:x:109:65534::/run/sshd:/usr/sbin/nologin pollinate:x:110:1::/var/cache/pollinate:/bin/false peterjatkinson:x:1000:1000:,,,:/home/peterjatkinson:/bin/bash
While stat /etc/passwd shows:
File: /etc/passwd Size: 1574 Blocks: 8 IO Block: 512 regular file Device: 2h/2d Inode: 7036874417973417 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/peterjatkinson) Gid: ( 0/ root) Access: 2020-07-12 10:01:59.045006400 +0100 Modify: 2020-07-12 10:01:59.045800500 +0100 Change: 2021-07-20 17:26:32.778110500 +0100 Birth: -
If that gleans anything useful that might help save me from reinstalling WSL, then please do let me know! Thanks again.
pkexec chown root:root /etc/sudoers /etc/sudoers.d -R
.pkexec
won't work under WSL1, will it? Not sure about WSLg, but that would be WSL2.pkexec
is not supported in WSL1.wsl -u root
not working. Agree with harrymc and danielb -- Probably going to require a reinstall. Just curious, though - What'scat /etc/passwd
andstat /etc/passwd
show? I'm guessing that it may be owned by UID 1000 as well? That could cause thewsl -u root
failure, but if that's the case, I can't think of any way to recover :-(