Issue
I made a very annoying mistake in a script... A line supposed to change permissions recursively on a folder :
chmod -R 777 $folder/
The thing is the variable was not set, so it ran instead :
chmod -R 777 /
Yes stupid. The problem is now I can't use sudo
anymore, I get this message :
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
- Is there any way to restore the permissions ?
- If not, is there any way to backup my Ubuntu 14.04 (running on VirtualBox) ?
- If not, how can I save important data ?
Solution
I've finally found a solution!
Issue explained
When I changed recursively the permissions on the root folder /
I also changed the permissions for /usr/bin/sudo
. To see its permissions I typed :
ls -la /usr/bin/sudo
It gives me :
-rwxrwxrwx 1 root root 127668 2016-05-11 12:01 /usr/bin/sudo
Instead of :
-rwsr-xr-x 1 root root 127668 2016-05-11 12:01 /usr/bin/sudo
Here the s of -rwsr-xr-x is important because it gives temporary permissions to a user to run sudo with the permissions of the file owner (i.e root in this case) rather that the user who runs it.
Take a look on this article for further information : http://www.linuxnix.com/suid-set-suid-linuxunix/
A solution would have been to change the permissions on /usr/bin/sudo
:
chmod 4755 /usr/bin/sudo
But I need to be root to change the permissions... Well, fortunately I was running Ubuntu on a VM.
Solution
A solution is to create a new virtual machine. Once it's done, on my new virtual machine mount my broken ubuntu .vdi with VirtualBox. Settings --> Storage --> Add a hard drive. Make sure the first hard drive is your new virtual machine so that it boots on the new virtual machine.
Once it's done, you can change sudo permissions on the hard drive mounted (your broken ubuntu) :
sudo chmod 4755 /mnt/XXXXX/usr/bin/sudo
You can now run your fixed virtual machine with a working sudo...
Answered By - bam500 Answer Checked By - Mildred Charles (WPSolving Admin)