I have run following command accidentally
sudo chown [username] -hR /
Now sudo su
getting error:
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
How to Solve This?
I have run following command accidentally
sudo chown [username] -hR /
Now sudo su
getting error:
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
How to Solve This?
As you'll read on this answer on SO, this problem is not as hard as people are making it. You can get the
sudo
command working again without a reinstall by following these simple steps:chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo
This does the trick and is much quicker and less painful than the "nuclear option" recommended in other answers.
If your root password is not set, you can boot in Recovery Mode to set it.
Note that this will resolve the titular error
/usr/bin/sudo must be owned by uid 0 and have the setuid bit set
but if like the OP you did more than mess up the permissions of the/usr/bin/sudo
file, a more "nuclear" option may in fact make more sense.Back up your data and reinstall.
This probably looks extreme but this isn't just
sudo
. You destroyed the permission structure of your entire filesystem. Some of the other answers can getsudo
working, but ignoring the whole problem is inviting a later disaster.You could try to mirror the owners off another install but there are cases (
/var/
for example) that are highly dependant on what you've actually got installed. If you want to get a scale of the problem, I've actually had a crack at helping somebody fix this sort of issue before. The fix is manual, long and could easily leave your system insecure or broken.Picking through that mess is going to take considerably longer than a clean install.
This has had a couple of drive-bys from folks that don't understand the seriousness of the situation here. To them it looks like a big pile of unnecessary work, the sort of thing a rogue plumber or mechanic says to shake you down for a bigger job.
If you've only changed the permissions on
/usr/bin/sudo
, by all means, just fix that. But this question is about a total system change. Every file (save the runtime-only ones) are now owned by the user. Everything the user runs (eg browsers, browser exploits) could then overwrite system files, spy on you, extract any data. This needs to be corrected. Per above, this is difficult. The easiest way is a reinstall.So please, don't be lazy about this. Filesystem permissions help keep you safe, fix them.
go to recovery mode by keep pressing Esc while booting the system.
select root option in long list you can see after entering into recovery mode (it is actually root shell)
type command -
mount -o remount /
(Or in recovery you can click on grub option. This helped me get read-write permissions on the file system. This basically updated the read/write mode on the file system since the command wasn't working for me initially)It will remount your file system in read and write mode.
command -
chown -R root:root /usr
this command will change ownership from "user" to root again recursivelynow still i had problem with
sudo
command, so I again followed step 1,2,3 and executedchmod 4755 /usr/bin/sudo
Now I really think that re-installing would have been really a "nuclear option"
Had the same issue on my droplet on digital ocean.
sudo: /usr/bin/sudo
must be owned byuid 0
and have thesetuid
bit set. Below are command that ive execute and reboot after.Hope it helps.
The above methods didn't work for me, because I couldn't "log back in as root" (unknown password) But I got a root shell by editing
After rebooting I was finally able to run
Unfortunately, if you do not have a full backup, probably the best thing you can do at this point is to reinstall.
Consider that you have changed all the files ownership to the same user, completely messing the security paradigm of your system....
If you search this site there are a lot of similar problems with chmod, as for example How can I recover from chmod -R a-wrx / command?
I was not able to edit
lightdm.conf
file under running system. I fixed things like this:/etc/lightdm/lightdm.conf
on the installationsudo -H gedit /mnt/etc/lightdm/lightdm.conf
and add the following lines from Anno2001's answerreboot
run command:
Change back default user in
/etc/lightdm/lightdm.conf
(you don't want to autologin as root every time, which would be very insecure and dangerous)If you have root user password then:
Login as root user
open terminal
Enter following commands:
If you do not have root user password then:
Reboot your system in recovery mode(boot and press and hold esc button to enter in recovery mode)
here it looks like
Navigate to (advance option for linux) by using down arrow button and press two times Enter
here it looks like
Navigate to root by using down arrow button and press Enter
here it looks like
Now enter following commands:
Press ctrl+d and then select resume option to boot normal
I have changed /usr/lib/ to root owner but but sudo only executes with root login in the terminal.
step one: su root step two: cd /usr/lib step three: chown -R root:root sudo
and that is it. Just NOTE you have tu run su root every time you want to use sudo.