So, I did a stupid thing...

I was installing some software (Java SE 7, if you must know) from a tarball, and I got tired of using sudo, so I went and changed the owner of my /usr directory to myself.

$ sudo chown -R sammy /usr


Since sudo lives in /usr/bin/, it also changed owner. Now, I can't use it anymore. Have I accidentally been caught in a sudo-Catch 22? I can't use apt-get install or any number of other essential features of my shell environment.

$ sudo
sudo: must be setuid root

Is there a way to change the owner of this directory (and subdirectories, too) back to root?

  • What is the exact command that you ran? – Richard Sep 19 '13 at 17:23
  • Yes. That's what I tried right away. However, any invocation of sudo throws the error quoted above. – Sammy Black Sep 19 '13 at 17:24
  • I will edit the question to include the exact command, @searchfgold6789. – Sammy Black Sep 19 '13 at 17:25

Restart the machine, boot into recovery (you should end up being root without having to type in any password). Proceed to chown -R. I think it should work. Report back on how it goes.

  • I've never booted into recovery. Presumably, I have to make a choice in grub, where I have a menu of possible kernels to boot with? – Sammy Black Sep 19 '13 at 17:43
  • Yes, you will have lines with <kernel number> and <kernel number> (recovery), select one of the recovery ones. – Wolfer Sep 19 '13 at 17:49
  • I changed the entire /usr directory tree back to root ownership, but sudo is still (!) throwing the same error. – Sammy Black Sep 19 '13 at 18:57
  • 1
    @SammyBlack Next step is chmod +s /usr/bin/sudo, which will set the setuid bit – Yet Another User Sep 19 '13 at 19:17
  • 1
    Thank you @Wolfer, @Yet\ Another\ User for the help. Everything seems to be back to normal. – Sammy Black Sep 19 '13 at 19:38

Man, you really did it, all /usr have almost essentials binaries, but lets repair your sudo first:

As root in the recovery console, you should remount the filesystem as read/write first:

chown root:root /usr/bin/sudo
chmod u+s /usr/bin/sudo

Then reboot and try to login, if you get more "Must be suid" errors repeat the process using sudo from the tty:

sudo chmod u+s /path/to/the/binary/you/screwed

Be careful next time and try to use -R --recursive with baby gloves.

Not the answer you're looking for? Browse other questions tagged or ask your own question.