If you’ve ever come across this error “/usr/bin/sudo must be owned by uid 0 and have the setuid bit set“. It is usually caused by you somehow changing the permission settings in the /usr/bin/sudo file, and in the process locking yourself out of sudo or root command actions.
The solution is quite simple, though I have come across forums giving the advice of a “nuclear option”, in other words re-installing your system. Feel free to take that route if your heart desires it. So lets start with the simple solution, starting with. . .
- Logout of your system, and during reboot Tap ESC or hold SHIFT on boot to show the GRUB menu..(By default GRUB is hidden unless there is more than one boot entry to choose from.)
- Tap e for EDIT and find the line that begins with LINUX . . . (the default kernel), and add a SPACE and the NUMBER 3 to the end of that line.
- Tap CTRL + X to save and reboot your system. When the system reboots it will be into a text based login system TTY, here you can login as user: root and password: ******* (your root password).
- Once done you will be presented with a root command prompt or #, here is where the magic happens, type the following line into this command prompt
chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo
- Logout of root or just Reboot you system, and log back in as youself (user), you should now have access to sudo. To test this, you could open a terminal and type sudo -i which you will then be asked for your password and presented with a root command prompt.
- First restart your PC/Laptop, and tap the ESC or hold SHIFT key while Ubuntu is booting. This will bring you up the boot menu.
- Select Advanced Options.
- Select your OS version in (recovery mode), and press Enter Key. (Example : Ubuntu 21.04 (recovery mode)).
- On the next screen select “Drop to root shell prompt” and press Enter. You will now see a command line at the bottom of the screen.
- Now run each of the following commands.
- mount -o remount,rw /
- mount –all
- chown root:root /usr/bin/sudo
- chmod 4755 /usr/bin/sudo
- Now restart/reboot your PC/Laptop. Once you log in, you will find that you can use the sudo command again .
I hope this may help some of us who don’t learn all about permissions before attempting any changes in the root usr or shared directories. Further reading can be found at Arch Linux’s File Permissions and Attributes. And the excellent Ubuntu articles at DevAnswers which also includes a comprehensive Numeric Meanings, (you know 777, 775, 600, etc. . .).