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)
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 root2 - open bash (zsh in my case) and change ownership:
chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo3 - on an elevated CMD change default user back to my username
ubuntu1804.exe config --default-user [my_username]Then I could use
sudocommands 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 configis in/usrand NOT/usr/localwhen you install usingapt-get. So… the ownership was extended to /usr/bin – which of course impacts sudo.Diogofgr’s solution + this:
chmod 775 -R /etc/sudoerschmod 775 -R /etc/sudoers.d/fixed sudo for me
this worked for me so thank you :] , however I did have to change it a little:
on an elevated cmd prompt:
wsl.exe -u rootchown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudoThis 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
Thanks! That worked perfectly fine… I’ve had
ubuntu2004as my exe!!!