19

I'm trying to run sudo, and it's failing:

gregd@david $ sudo ls
sudo: must be setuid root
gregd@david $ which sudo
/usr/bin/sudo
gregd@david $ ll /usr/bin/sudo
-rwxr-xr-x 1 root root 165K 2012-05-16 00:25 /usr/bin/sudo*

Any suggestions on how to fix this?

Greg Dougherty
  • 3,281
  • 8
  • 35
  • 58

2 Answers2

78

This problem is caused sometimes when the permissions of the file, /usr/bin/sudo get set to 777. If you do something like chmod -R 777 /usr/, you can do this. It effectively ruins sudo. Here is the solution if this is your problem, and the accepted answer doesn't work:

To fix:

Restart pc, press shift at boot menu.

This should bring up GNU GRUB (ie recovery mode) menu.

  • If this doesn't work, just restart mid boot and choose recovery mode when prompted on next launch.

Select the line which starts with Advanced options

Select the topmost version of the OS ending with ("recovery mode")

Press enter

In the following menu, go down to "Drop to root shell prompt"

Type the following:

mount -o remount,rw /

mount --all

chown root:root /usr/bin/sudo

chmod 4755 /usr/bin/sudo

restart

This should restore sudo privellages.

Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
Adam
  • 781
  • 1
  • 5
  • 3
  • For me, logging out of the current user and logging in as the root user was enough to be able to run `chown root:root /usr/bin/sudo` and `chmod 4755 /usr/bin/sudo`. From there, I simply logged out of root and back in as my normal user and sudo worked without issue. – user456584 May 24 '14 at 13:44
  • 1
    @Adam Haha I'm a beginner too and did exactly what you did to break `sudo`: `chmod -R 777 /usr/`. The solution was easy to understand and it worked. Thanks! – Jonathan Lam Jul 04 '14 at 16:13
  • @Adam Worked like a charm, thanks, I was freaking out, thinking I had to reinstall linux mint. I did a chown on /usr/bin/* to get my github keys to work with my username instead of root. Lots to learn about linux administration – pixel 67 Oct 20 '14 at 09:06
  • 3
    u_vote for simplest disaster-fix ever. – Bedir Yilmaz Jun 03 '15 at 23:08
  • 3
    Worked like a charm... but... (I am running a **debian jessie**) I had to swap the **restart** with **reboot**. –  Feb 05 '16 at 16:30
  • This was the best one which solved my problem. – P S Dec 28 '17 at 08:14
  • restart did not work for me so i did: `/sbin/reboot` – Raj Nov 08 '19 at 02:53
  • Unfortunately this not only did not work for me, now after doing this suddenly my WiFi adapter disappeared from Ubuntu. So no sudo and no WiFi. I would appreciate any help... – avi Sep 06 '22 at 03:54
11

You have to be able to log in as root, but if you can you can run this

chmod u+s /usr/bin/sudo

And fix the problem

Greg Dougherty
  • 3,281
  • 8
  • 35
  • 58
  • What causes this problem? – cwallenpoole May 28 '13 at 16:39
  • I think it has to do with copying over your bin directory as non-root, then doing a chown on all the files to make them owned by root. But that's more or less a guess – Greg Dougherty May 30 '13 at 13:28
  • Interesting. That's at least second question from you answered by yourself in the same minute. Found a system abuse hole? – keltar Oct 11 '13 at 03:46
  • 4
    When posting questions, StackOverflow asks if you have an answer you want to post as part of a Q&A. So I try documenting those problems I think others might care about, too. – Greg Dougherty Feb 12 '14 at 00:16
  • In OSX 10.6 I was able to solve this by running the Applejack program in single user mode. – MikeiLL Sep 24 '14 at 22:46