How to fix sudo must be owned by uid 0 and have the setuid bit set in WSL

How to fix sudo must be owned by uid 0 and have the setuid bit set in WSL

So I recently took up the challenge of turning my PC with only Ubuntu KDE installed into a dual-boot Windows 10 PC. I've been on Ubuntu since 2008 and after a decade free of Windows at home I decided to take up the challenge of using WSL (Windows subsystem for Linux).

However after developing and running all my favorite cli tools for nearly 3 months I ran into /usr/bin/sudo must be owned by uid 0 and have the setuid bit set error.

Normally on a Linux host you'd login to a root shell and fix things but WSL didn't appear to have a way to login as or switch to root from the scope of bash.exe.

Dare I venture into the land of PowerShell? Seems inevitable.

I've been running WSL since before the Fall Creators Update so the lx subsystem environment is managed with lxrun (can't possibly be that tool from the 90's).
Appears that switching the user is as simple as running lxrun /setdefaultuser root in PowerShell, then you can go into a new bash.exe session and fix the following like you would on a Linux host;

  • Fix the owner of sudo chown root:root /usr/bin/sudo
  • Fix permissions of sudo chmod 4755 /usr/bin/sudo

Exit the session and go back to PowerShell and run lxrun /setdefaultuser ubuntu to set the user back.

Start a new bash.exe session with sudo fixed.

Now if you are running WSL installed after the Fall Creators Update I believe the PowerShell commands are now different. You can try ubuntu config --default-user root first then ubuntu config --default-user ubuntu to revert, but I have no way to verifying this without breaking my now working environment.

Subscribe to Christopher D. Langton

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe