Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I accidentally set owner of root folder (/) and all subfolders to one user by command

$ sudo chown -R 'userName' /*

Now I wanna set owner back to root user by command

$ chown -R root:root /*

But I have no permission for this operation. If i use command

$ sudo chown -R root:root /*

it returns

sudo: effective uid is not 0, is sudo installed setuid root?

What should I do to fix that?

share|improve this question
    
@terdon Actually, chown -R foo/* should not replace the owner on /, just the subdirectories. They are subtly different. –  Darth Android Jul 3 '13 at 16:33
    
    
@DarthAndroid you are absolutely right, comment deleted. –  terdon Jul 3 '13 at 16:36

3 Answers 3

up vote 2 down vote accepted

Uh... that's an interesting situation. sudo requires the binary to be owned by root and have the setuid flag on it to function properly (this allows it to execute as the file owner, no matter who actually launched it).

By changing the owner, sudo can no longer run as root, and subsequently, can't run your commands as root.

The easiest method to recover from this is to

  1. Reboot the machine into single-user-mode
  2. Copy all your important files off onto a USB or external drive.
  3. Reinstall Ubuntu, and then restore your files.

As you found out, there are a number of system files which absolutely depend on having the correct owner and the correct permissions. SSHd for example, will refuse to start if the host private key does not have exactly correct permissions (0600 and owned by root I think). sudo cannot elevate itself without being setuid and owned by root, and I'm sure there are many other security-related programs that won't operate if they see that things aren't perfect.

Through a lot of very tedious work, it would be possible to recover some of the permissions using an external computer, but it's not a fun task and a reinstall is probably going to be much simpler.

share|improve this answer
    
Indeed, reinstallation is probably the way to go. –  gniourf_gniourf Jul 3 '13 at 16:27

if you chown'd recursively before, then your permissions are more-than-likely irreversibly damaged.

Backup your data and reinstall.

share|improve this answer

Seriously, rebuild from scratch. even if you get past the error you are looking at, and manage to re-chown root, your system will still be as broken as it is now. there is effectively no means to recover from an out of control chowning (or chmoding for that matter). Even if you were somehow able to get a partial list of the original owners for each object, it would almost certainly be incomplete, and would reflect a stock system state, which may have been changed by app/daemon install after the files were initially created.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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