WSL: Error: sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set

Last night I installed nodejs and did a sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share} to allow for npm install -g without needing sudo. I was able to install the express, express-generator, and strongloop packages just fine.

This morning I went to do a pip install pdfx and got the usual message about not having permissions to /usr/local/lib/python2.7 so I tried to chown that directory and got the error:

sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set

sudo no longer works for any command and from what I can read there is no way to log into WSL as root to patch the sudoers file and make sure persmissions are properly set on /usr/bin/sudo.

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 18 (5 by maintainers)

Most upvoted comments

I had this problem on Win10 build 17763 with Ubuntu 18.04. On my Windows version there is no lxrun.exe so, adapting @garytube 's solution, I did the following:

1 - on an elevated CMD change default user to root: ubuntu1804.exe config --default-user root

2 - open bash (zsh in my case) and change ownership: chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo

3 - on an elevated CMD change default user back to my username ubuntu1804.exe config --default-user [my_username]

Then I could use sudo commands again! 🎉

Bingo - I found the problem…

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

does not work here since the npm config is in /usr and NOT /usr/local when you install using apt-get. So… the ownership was extended to /usr/bin – which of course impacts sudo.

Diogofgr’s solution + this: chmod 775 -R /etc/sudoers chmod 775 -R /etc/sudoers.d/

fixed sudo for me

I had this problem on Win10 build 17763 with Ubuntu 18.04. On my Windows version there is no lxrun.exe so, adapting @garytube 's solution, I did the following: 1 - on an elevated CMD change default user to root: ubuntu1804.exe config --default-user root 2 - open bash (zsh in my case) and change ownership: chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo 3 - on an elevated CMD change default user back to my username ubuntu1804.exe config --default-user [my_username] Then I could use sudo commands again! 🎉

It might worth mentioning that on PowerShell you do not need to run it as admin, simply run it like this: ubuntu.exe config --default-user root

Once you fix the permissions on all files you can verify if the user can switch by simply run: su - <my_user>. If no errors appear everything will work just fine, alternatively fix the permissions on any other dir that might appear and apply at the end: ubuntu.exe config --default-user <my_user>


this worked for me so thank you :] , however I did have to change it a little:

  1. on an elevated cmd prompt: wsl.exe -u root

  2. chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo

This was nice because then you don’t have to mess at all with the default user (and it seemed to work just the same)

@lamirev open cmd and set root as default

lxrun.exe /setdefaultuser root

open bash - you should be root - as root do:

chown root:root ~/usr/bin/sudo && chmod 4755 ~/usr/bin/sudo

login into your user - sudo should work now

I had this problem on Win10 build 17763 with Ubuntu 18.04. On my Windows version there is no lxrun.exe so, adapting @garytube 's solution, I did the following:

1 - on an elevated CMD change default user to root: ubuntu1804.exe config --default-user root

2 - open bash (zsh in my case) and change ownership: chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo

3 - on an elevated CMD change default user back to my username ubuntu1804.exe config --default-user [my_username]

Then I could use sudo commands again! 🎉

Thanks! That worked perfectly fine… I’ve had ubuntu2004 as my exe!!!