131

I have run following command accidentally

sudo chown [username] -hR /

Now sudo su getting error:

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

How to Solve This?

Pandya
  • 35,771
  • 44
  • 128
  • 188
  • Note: When I had this issue, I had reinstalled the OS (Because at that time on-other answers exist and I can't wait more). So, Now new answers will be no longer supported from my side! – Pandya Jan 30 '15 at 12:18
  • Thanks to the tiny Warning posted under Option 1 here which I gladly ignored and ended up here! – Anand Rockzz Jun 30 '17 at 09:35
  • 1
    Use https://medium.com/@KongToonArmy/sudo-must-be-owned-by-uid-0-and-have-the-setuid-bit-set-cdca3dba7d19 by KongToonArmy KongToonArmy – Rupsingh Aug 20 '19 at 08:08
  • I wanted to answer this, its closed now, and IDK why. Its the oldest post I can find pertaining to this specific error message. Its important to note, that sometimes you can get this error message by adding 2 or more administrators to a single system. Another thing that can happen is that you could have change the permission of your binaries. In both of these situations, you could recieve this error message. Its important to note, that this error message comes the fundamental fsys, and not from distro specific software. From my understanding, this error is basically saying that – JΛYDΞV Mar 01 '22 at 07:04
  • the sudo command is basically saying that sudo isn't owned by root anymore, which isn't the same as saying you are not the root user. In other words, many people that have answered this question misinterpret what it means. Every time I have encountered this issue its been realitivley easy to fix. Recently I changed an account name, but didn't want to delete my old account, so I just switched permissions for admin from the old account to the new account. I got really confused becuase I was getting this error, but quickly found out, its because I some how set both accounts as admin. – JΛYDΞV Mar 01 '22 at 07:25
  • 1
    I just changed permissions for the other account, restarted the computer and everything worked. – JΛYDΞV Mar 01 '22 at 07:26
  • @jD3V how u chsnged permissions for the other account? – a learner Jun 28 '22 at 07:29

12 Answers12

218

As you'll read on this answer on SO, this problem is not as hard as people are making it. You can get the sudo command working again without a reinstall by following these simple steps:

  1. Log out as the current user, then log back in as root.
  2. Execute chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo
  3. Log out as root, then log back in as the current user.

This does the trick and is much quicker and less painful than the "nuclear option" recommended in other answers.

If your root password is not set, you can boot in Recovery Mode to set it.

Note that this will resolve the titular error /usr/bin/sudo must be owned by uid 0 and have the setuid bit set but if like the OP you did more than mess up the permissions of the /usr/bin/sudo file, a more "nuclear" option may in fact make more sense.

user10962
  • 2,569
  • 25
    If you do not have a root user, restart and press Esc to enter the grub menu. There select Advanced options for Ubuntu and select recovery mode. Then select root and you can find yourself in the root shell. If you get an error that the filesystem is in read only mode, do: mount -o remount,rw / – George Oct 23 '14 at 02:25
  • 22
    Sure, that will fix sudo, but it isn't going to fix the dozens of other things that were broken. – psusi Jan 30 '15 at 20:57
  • 7
    Had same problem in my lxc container, additionally had to do this: chown root:root /usr/lib/sudo/sudoers.so && chmod 4755 /usr/lib/sudo/sudoers.so; chown root:root /etc/sudoers; chown root:root /etc/sudoers; – Aurelijus Rozenas Jul 12 '16 at 05:40
  • 7
    using su root instead of sudo su, followed by the root password can save you some headache, if your ssh, or instead of going to grub. – Brian Thomas Aug 19 '16 at 01:03
  • 5
    in addition to what @infro said I also needed chown for /etc/sudoers.d, /etc/sudoers.d/README and /var/lib/sudo – Roman Bekkiev Sep 14 '16 at 08:59
  • still not solved my problem: sudo chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set – Mr world wide Sep 20 '17 at 14:43
  • I was about to reinstall the whole system on my office laptop, you sir are my hero and saved me hours of work. Besides, I just learned something new – oidualc Nov 21 '17 at 08:56
  • 2
    I fixed the permissions following your instructions and everything was ok, and then I checked the security of my install with https://github.com/CISOfy/lynis what else do I need to do? just to be sure that my system has no need to be re-formated – Israel Morales Mar 24 '18 at 03:56
  • 1
  • su 2. chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo 3. exit
  • – Deepak Mahakale Aug 24 '18 at 06:12
  • 2
    Helpful tip: if you are using WSL, check out this tutorial to log in and out of root: https://www.tenforums.com/tutorials/128152-set-default-user-windows-subsystem-linux-distro-windows-10-a.html – Jacolack Aug 16 '21 at 21:35
  • Also helpful tip for WSL. https://askubuntu.com/questions/931940/unable-to-change-the-root-password-in-windows-10-wsl wsl -u root will login to wsl as root – Jay Killeen Jan 10 '22 at 03:13
  • That helped a lot. I would add a mention : Even after setting root password in recovery mode, it's impossible to remote SSH as root. So I did chown root:root /usr/bin/sudo && chmod 4755 /usr/bin/sudo directlly in recovery mode root shell. Reboot and I can use sudo with no problems via SSH as a user – Jurion Jan 02 '23 at 23:20