Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have done this:

sudo chown -R myname /usr/

and now I can't use the sudo command because of this error:

sudo: must be setuid root

And as I read this means that the owner of this file /usr/bin/sudo is not the root. It's my user now because of the chown on the /usr folder.

On many forums and blogs people suggest to do this as root:

# chown root:root /usr/bin/sudo
# chmod 4111 /usr/bin/sudo

...but the problem with this is that I need to log in as a root, but I can't because If I write su in the terminal the password is wrong (actually I use the password what I added to my user):

$ su
Password:
su: Authentication failure

So can I get back the sudo command?

Edit: My Ubuntu is under Paralells on my Mac OS X.

share|improve this question
    
What do you mean by "I use the password what I added to my user"? When you use su, you will be prompted for root's password, not your user's password like with sudo. Do you know the root password for this machine? –  Caleb Jul 19 '11 at 13:36
    
No, I never needed to add or modify it, is there a default for it? –  CIRK Jul 19 '11 at 13:37
    
You need to reboot in single user mode. What distribution are you running? –  Gilles Jul 19 '11 at 13:40
    
I'm using ubuntu 11.04. How can I reboot in single user mode? :) –  CIRK Jul 19 '11 at 13:42
1  
Just curious, but what made you decide to run a sudo chmod -R cirk:cirk /usr What were you trying to accomplish? –  loosecannon Jul 19 '11 at 15:00
show 3 more comments

2 Answers

up vote 2 down vote accepted

If you have a similar system that you can use as a guide to see what the correct ownership for all of the files is, then you can boot into rescue mode, drop to a root shell, and manually restore the correct ownership to all of the files in /usr.

The quickest way may be to reinstall your OS or restore from backup.

In Ubuntu or similar, then there is no root password by default (the account is disabled), which is why you can't su.

share|improve this answer
3  
Woah take it easy there, this isn't windows re-installing is not always the easiest or fastest way to do anything and certainly doesn't teach people how to fix problems. In this case all he needs to do is reverse the action he took which can easily be done by mounting the file system up in another environment like a LiveCD or the rescue mode you suggested (distro dependent). –  Caleb Jul 19 '11 at 13:43
    
@Caleb when you completely trash the permissions on an major chunk of the filesystem it is. He didn't just screw up sudo, presumably he forgot to mention in his post that he used -R ( otherwise it would have only changed the owner of the /usr directory itself and not sudo ). I also did describe how to reverse the process, but it is a very time consuming and painstaking task. –  psusi Jul 19 '11 at 13:50
    
This is a case of chown not chmod. Since everything in the /usr folder should be root:root, this should be an easy fix, not the painstaking fix that a chmod clobber would mean. –  Caleb Jul 19 '11 at 13:53
1  
@Caleb not everything in /usr should be root:root. –  psusi Jul 19 '11 at 13:56
3  
@Caleb chown resets the setxid bits. There are a few files in /usr that aren't owned by the root; more that are in a different group (especially setgid programs in /usr/bin). –  Gilles Jul 19 '11 at 14:12
show 5 more comments

Since you have hosed the permissions on the only thing that gives you root level access, you will need some help from OUTSIDE the current software environment to fix this.

I suggest that the easiest way is to boot up a LiveCD for your distro, mount your drive, and change the file permissions using the chmod you listed from there.

You could also try booting into single-user mode in order to get a root shell.

Be aware that usually all things in the /usr/ directory should be owned root so you should just be able to do a recursive chown to fix whatever you broke. (Edit: Per @Gilles comments apparently running chown breaks setuid and setgid bits, so you will need to manually compare to an existing system to restore all of those once you fix the ownership again.)

However, very FEW should be 4111. That extra one is a special permissions but that makes it execute as root even when run as a user! Only sudo and a select few commands should have this permission bit set. If you didn't run a chmod to start with you probably don't need to fix this at all, all the permissions should already be correct. Don't run a big chmod operation without knowing what all the permissions are supposed to be.

share|improve this answer
    
Is it possible if the OS is in a Virtual Machine? –  CIRK Jul 19 '11 at 13:53
    
Yes that makes no difference. You could use runlevel 1 (something you can do at the very beginning of the boot process from grub/lilo or wahtever your bootloader is) or you can setup the VM to use an ISO image of the LiveCD as the boot device. –  Caleb Jul 19 '11 at 13:57
    
aham, well before I reinstall it, I will try your advice :) –  CIRK Jul 19 '11 at 13:58
    
ok I think I'm in the LiveCD, now I need to write this in the terminal? sudo chown -R root /usr/ ? –  CIRK Jul 19 '11 at 14:35
    
Ya start with that, but not on /usr on the LivdCD, you need to mount it somewhere and run against that path, say /mnt/mydrive/usr. Then you will need to fix the setuid bit on /mnt/mydrive/usr/bin/sudo. Then look through the /usr on the livecd and see if there are any other ownerships other than root. find /usr -not -uid 0 and change those to match. Then look for things that have different setuid or setgid bits set and make sure those match too. If you have a real Ubunutu system to compare to that would be best. –  Caleb Jul 19 '11 at 14:39
show 6 more comments

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.