16
[root@notebook ~]# grep root /etc/sudoers
root    ALL=(ALL)   ALL

Question: Why does the root user need sudo permissions? I've seen it on different UNIX OSes. Can someone please explain this?

25

So that they can (from the man page):-

execute a command as another user

sudo isn't limited to allowing regular users to execute a command as root. Root can run a command as another user with:-

sudo -u bloggs <command>

Note that root will not need to supply the user's password.

  • 2
    su -c '<command>' bloggs – Joshua Jan 14 '15 at 0:35
  • Yes, it is a surrogacy method and root is merely a very common usage. – mckenzm Jul 25 '15 at 23:56
9

Suppose you have a script that does a bunch of things without needing special privileges, and then a single privileged thing that it does through sudo.

If you want this script to be useful for root too, it is convenient that this final sudo command won't refuse working because "you're root; root is not allowed to sudo".

Configuring this in sudoers instead of hardcoding an exemption for root in the sudo binary reduces the complexity of the security-critical code in sudo (however slightly), which is always a good thing.

  • 1
    And besides, I've more than once accidentally started an admin-level command with sudo while I already was root, just because it's ingrained into my muscle memory... – Shadur Jan 14 '15 at 9:22
3

The reason given in the original sudo manual (sorry no online version I know of) was for logging active commands wherever possible when logged in as root.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.