User has issued a below command on /usr directory. #sudo chown -R $(whoami) /usr When we try to revert the change, we are getting below error message. “sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set” Any ways to get back this to normal condition?
As you know /usr permission changed to normal user. Never do that as a result many other commands and services won’t work. There are few ways to fix this but none are easy:
- Some distro allows to restore /usr permissions if you can boot into a single user mode. May I know your distro name?
- Second method involves booting system into advanced option or recovery mode. Once in recovery mode you need to remount system and set permission for sudo using the following commands:
mount -o remount,rw / mount --all chown root:root /usr/bin/sudo chmod 4755 /usr/bin/sudo sync && sync reboot
- Third option is backup all data and reinstall system as /usr/ is beyond recovery. Once installed restore the data.
Firstly, thanks for the quick response. Much appreciated,.
To answer your question, it’s Ubuntu 18.04 hosted on Azure Cloud.
I’m not sure, we can get into Single User Mode/Recovery mode on Azure Cloud as it’s a Virtual Platform.
i have cis project con not do t would you please help me with that
I have resolved the issue by entering into Single User Mode and ran the commands you suggested. Now the VM is back to normal working condition. Many Thanks…
Could you please describe, what will happen when we run #sync && sync command?
Glad it worked out. The sync command synchronize cached writes to persistent storage. In words, write data/metadata to the disks before we issue the reboot command. Most modern Linux distros do write data before shutting down or rebooting the server but issuing the
sync twice guarantees metadata and other data saved to the disk especially in maintenance or single user mode. It is a safety feature.