Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I enetered chmod -R 777 /usr/bin and now sudo is not working.

It is giving error that sudo must be setuid root.

On looking via Google, some advice said to run chown root:root /usr/bin/sudo chmod 4755 /usr/bin/sudo.

On entering chown root:root /usr/bin/sudo it is showing an opened in readonly mode error.

share|improve this question
    
You must be root to run those commands –  Mat Apr 27 '12 at 13:44
add comment

migrated from stackoverflow.com Apr 29 '12 at 2:41

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 7 down vote accepted

On an Ubuntu desktop system, PolicyKit is installed, so pkexec can be used to repair a broken sudo executable or sudoers file. You do not need to boot into recovery mode and you do not need to boot from a live CD. You don't even need to reboot.

In this case, run the following commands:

pkexec chown root:root /usr/bin/sudo
pkexec chmod 4755 /usr/bin/sudo

See this question for more information.

share|improve this answer
    
pkexec must be setuid root! What a nightmare! –  Damien Roche Aug 23 '13 at 14:26
add comment

Even when running from the live CD / Pendrive, you must prefix your chmod command with sudo. So your steps will be like the following:

  1. boot from a live CD / Pendrive
  2. check whether your disk was already automounted (and where to). If not, mount it (see below)
  3. use sudo chmod 0755 <path> to adjust the permissions

How to figure out where your disk is mounted: from a terminal window, run mount (without arguments). This will list up all mounted devices. Check for the type listed -- you can skip everything not using a "real file system" (your disk probably uses either ext3 or ext4 -- you can for sure skip things like proc, sysfs and the like). If something sounds promising (looking like /dev/sda1 on /media/sda1 type ext3), check its contents using ls /media/sda1 to see if it's that.

If it is not mounted, you can check with the /dev entries where the disk could be (using ls /dev/ |grep '/dev/sd to check for available devices; your disk should look like /dev/sdaX, /dev/sdbX or the like -- with X being a number). Compare this with the list of mounted devices. If it's not there, try to mount it and check its contents (as shown above). To mount it, first create a mountpoint, e.g. sudo mkdir /mnt/mydisk, then try to mount the device using mount /dev/sda1 /mnt/mydisk and check its contents using ls /mnt/mydisk.

Once you get the right disk there, you can go to change the permissions back on your usr dir: sudo chmod 0755 /mnt/mydisk/usr.

Now you still might be in trouble if you originally ran the chmod command recursively, using the -R parameter. In that case you can either try to fix each entry manually -- or you can go straight for a fresh install...

share|improve this answer
    
I tried to create mount point, but I got an error which read mount point mnt/mydisk does not exists is mydisk to be replaced with some thing and just for the record i wrote mount /dev/sda /mnt/mydisk from root@Ubuntu:/dev# –  vin Jul 9 '12 at 15:30
    
You did a) create that mount point (directory) before issuing the mount command (as described) and b) took care for the leading slash as well? Try mkdir -p /mnt/mydisk && mount /dev/sda1 /mnt/mydisk (I don't think you have no partitions on /dev/sda, so you must have missed the partition number as well. Make sure you specify the correct device (or mount will fail). –  Izzy Jul 9 '12 at 16:05
add comment

I think Mat's correct, you must be root to add the bit to /usr/bin, but of course sudo is broken. If you have a root password you can use that to logon as root and then fix the permissions with the above command. If you don't, however, (and I don't either) it would probably be best to:

  • boot from a Linux live CD
  • become root there
  • mount the partition with the above system
  • then straighten out the permissions on that file system using a terminal.

Root is always user number 0 so root on any system can make changes allowed to root on other file systems.

share|improve this answer
add comment

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.