3

I am getting an error when trying to run any command in sudo mode.

Error:

sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set

I found a number of questions and accepted answers on askubuntu.

But none of those solved my problem. Probably my case is different from them.

More information :

I tried to install utorrent following the top voted answer of this question.
After extracting the .tz file to /opt I renamed the extracted file.
Since then I am facing this error.

I expect an answer which doesn't suggest me to reinstall the system.
If reinstalling is the only solution, I would have to backup everything I ever installed.

9
  • 2
    Can you add the output of ls -l /usr/bin/sudo to the question. Sep 19, 2015 at 10:05
  • The answer to the question you linked doesn't seem to mention renaming anything. Are you sure you didn't make an error in the chmod command - for example, leaving a space between the / and the opt? Sep 19, 2015 at 11:04
  • @steeldriver No I wrote /opt. but i cannot remember wether I rote -R before 777 or after 777 in case of chmod command. may it cause problem?
    – partho
    Sep 19, 2015 at 11:10
  • @mikewhatever------rwxrwxr-x 1 root root 155008 ফেব্রু 11 2014 /usr/bin/sudo
    – partho
    Sep 19, 2015 at 11:10
  • 1
    possible duplicate of Ubuntu sudo not working
    – muru
    Sep 19, 2015 at 13:01

4 Answers 4

5

Simple fix, if you did not also mess up pkexec:

The problem is that your /usr/bin/sudo has the wrong permissions set (-rwxrwxr-x instead of correct -rwsr-xr-x).

Now, as the file is owned by root, you need root permissions to change its permissions. Usually, you would use sudo for this, but as it's broken, we have to use pkexec as replacement to repair it:

pkexec chmod u+s,g-x /usr/bin/sudo

Now everything should be fixed again. Try the e.g. following command to check:

sudo echo "sudo works again! Yay! :D"

More complex fix, if you have also messed up pkexec:

First, you need to boot your Ubuntu system in recovery mode.

You do this by rebooting and waiting for the GRUB menu to show up. This happens immediately after the BIOS finished its work and before Ubuntu starts to load. It will usually show up if you dual-boot with another OS, but if it does not, you have to hold the Shift key to let it appear. Select the menu point Advanced options and then chose the latest kernel version with the suffix (recovery mode). You will see another menu, where you have to select root, which shows you a terminal with root access.
More information on how to enter a root shell in recovery mode can be found here, please follow steps 1-7, then continue here.

Run the following commands in the root shell:

mount -o remount,rw /
chmod u=rwxs,g=rx,o=rx /usr/bin/sudo /usr/bin/pkexec
exit

Then reboot normally and test your commands.

5
  • 2
    Running the first line code i get pkexec must be setuid root , and sudo is not still working, same error!
    – partho
    Sep 19, 2015 at 12:22
  • Wait - you messed up pkexec too? Ohhh... (facepalm) Sorry, then you need to boot in recovery mode and drop to a root shell.
    – Byte Commander
    Sep 19, 2015 at 12:25
  • drop to a root shell means?
    – partho
    Sep 19, 2015 at 12:40
  • @partho Edited my answer.
    – Byte Commander
    Sep 19, 2015 at 12:53
  • great help , Linux geek !
    – partho
    Sep 19, 2015 at 13:46
0

Recently had the same problem, i messed up sudo and pkexec.

Tried @Byte Commander♦ answear above but that didn't work for me because it didn't change the permissions on 2 specific files so i had to change them one at a time.

The first file is sudoers which is in /etc

  • cd /etc
  • chmod u=rwxs,g=rx,o=rx sudoers

The second file is README which is in /etc/sudoers.d

  • cd /sudoers.d
  • chmod u=rwxs,g=rx,o=rx README

After you have done these changes try sudo echo "sudo works again! Yay! :D" as @Byte Commander♦ wrote on his answear and there you have it.

0

If you messed up sudoers and can no longer run sudo as any user, do the following:

  1. Run pkexec chmod 777 /etc/sudoers: It will make the file world writeable aka anyone can edit now
  2. Edit the sudoers file (set permissions of user/group) as you require
  3. Since the sudoers file has been made world writeable it won't work (default Linux security mechanism)
  4. Set the permission correct on sudoers file by:pkexec chmod 0755 /etc/sudoers

If you messed up pkexec also follow the solution given by @Byte Commander♦

0

solve sudo error

you should reinstall "sudo" command

for this do fallowing recipe:


1- install "synaptic package manager"

you can download it from :

https://pkgs.org/download/synaptic

or

http://archive.ubuntu.com/ubuntu/pool/universe/s/synaptic/synaptic_0.84.3ubuntu1_amd64.deb

or

search in Ubuntu software update app "synaptic package" and install it

image:

enter image description here


2- open app


3- on top of page click on search box and text "sudo" now find the "sudo" in list > and click on solid square & on the opened square select on "mark for reinstallation" > then click on Apply on top of page and install it

images:

enter image description here

enter image description here


4- open terminal and run "sudo" command

you get :

usage: sudo -h | -K | -k | -V
usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]
            [command]
usage: sudo [-AbEHknPS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p
            prompt] [-T timeout] [-u user] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p
            prompt] [-T timeout] [-u user] file ...

so : the sudo is working now


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .