2

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.

7
  • It may be faster to just wipe the WSL distribution. I assume you can still access/backup whatever data you saved there?
    – Daniel B
    Aug 25, 2021 at 18:35
  • Try: pkexec chown root:root /etc/sudoers /etc/sudoers.d -R.
    – harrymc
    Aug 25, 2021 at 19:11
  • @harrymc To my knowledge, pkexec won't work under WSL1, will it? Not sure about WSLg, but that would be WSL2. Aug 25, 2021 at 19:35
  • @NotTheDr01ds: Just tried and you're right - pkexec is not supported in WSL1.
    – harrymc
    Aug 25, 2021 at 20:00
  • Missed the part about wsl -u root not working. Agree with harrymc and danielb -- Probably going to require a reinstall. Just curious, though - What's cat /etc/passwd and stat /etc/passwd show? I'm guessing that it may be owned by UID 1000 as well? That could cause the wsl -u root failure, but if that's the case, I can't think of any way to recover :-( Aug 25, 2021 at 20:06

1 Answer 1

0

Just tried pkexec in WSL1 and got exactly the same error as you, so pkexec is just not supported in WSL1.

But wsl -u root works fine for me, without the message of "User not found".

This message means that you have somehow corrupted the user list, or changed permissions on some crucial system files. It would be next to impossible to analyze the problem, especially since root seems inaccessible.

I join my voice to DanielB, in suggesting that you delete this WSL distribution and start from scratch.

To properly delete an installed Linux distro from disk, go into the Windows Settings > Apps section > Apps & features, scroll down to your distribution, click on it and then on the now displayed "Uninstall" button.

1
  • Also, I just tried it in WSL2, and it doesn't seem to be supported there either, at least not without X running or WSLg. Also see this Github issue. Aug 25, 2021 at 20:02

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.