TL;DR
When you run sudo, you're changing the effective user and/or group ID of a process call. Sudo defaults to the root
user, but can use other users and groups as well (see the -u
flag, for example).
The root
user is the system's default superuser, but the choice of name is a convention rather than a hardcoded requirement. Don't change it, though, unless you are a masochist.
UID 0 is a Built-in Superuser
You're looking at this backwards. Root is an instance of a superuser (e.g. a user with elevated system privileges), but there can be any number of superusers on a Linux or Unix system. root
just happens to be the expected name of the user with a real ID of 0. That user ID (UID) is hardcoded into the kernel and receives special permissions on *nix systems.
The default superuser group (e.g. root
on most Linux distros, wheel
on most BSD derivatives) can contain other users too, which then have access to things with the relevant read, write, execute permissions set in the group bits of the mode. For example:
-rw-rw-r-- 1 root root 6804 Aug 17 2018 /etc/passwd
This file is readable and writable by the root user, as well as anyone in the root group.
Various utilities like sudo or SGID binaries can provide other users with an effective UID (EUID) or effective GID (EGID) that allows them to perform privileged operations. While not recommended, you can also have more than one user with the same UID, so anyone in /etc/passwd with a UID of 0 is effectively root as well, even if the account names are different. Some BSDs have historically included a toor user with a real UID of 0, along with the standard root user.
You can even rename your root account to something else, if you like. That's generally a bad idea because many scripts and utilities expect the first account with UID 0 to actually be named root
, and often use the account's name instead of its UID or GID to set permissions. For example, the following lines are usually equivalent:
chown 0:0 /etc/passwd
chown root:root /etc/passwd
However, while the kernel doesn't care if you rename the root
account to toor
or even luser
, you can generally expect things to break if you don't have your first superuser account named root
with a real ID of 0. Think of it as a de facto portability standard, for all practical purposes.
The Default Superuser Group
Most Linux systems use root
for the name of the default superuser group. User root
is a member of this group. The group is usually assigned a group ID (GID) of 0, but this isn't enforced by the kernel.
On BSD-based systems like macOS, the default superuser group is generally wheel
instead of root
. This difference can crop up in cross-platform scripting, but isn't as likely to cause unpleasant surprises as a renamed root user.
Whether or not root is the same as superuser or root is a superuser or those two are completely different concepts altogether depends solely on how you define the term "superuser". So, what's your definition? – Jörg W Mittag – 2019-05-20T08:01:41.927
24
sudo
means switch user and do. It's just that, likesu
, it defaults to the root user. – OrangeDog – 2019-05-20T11:08:26.5775@OrangeDog You just made that up though.
su
was always super-user and the documentation ofsudo
from 1993 simply says execute a command as the superuser. You can "backronym" as much as you want, but the sources don't lie. – pipe – 2019-05-20T11:47:00.84724@pipe In AT&T Unix V7 (1979) the source says "substitute user". Later (and forked) versions changed it to "switch user". The version you're looking at from 1993 obviously didn't get the memo. – OrangeDog – 2019-05-20T12:02:21.500
5@pipe Many manuals commonly refers to "substitute user" for su – Jean-Baptiste Yunès – 2019-05-20T12:11:07.583
2@OrangeDog I'm looking at the 1975 sources. – pipe – 2019-05-20T12:21:16.440
6@pipe well in 1975 (UNIX V6) all it did was elevate to superuser. When they make it more generic, they changed the meaning accordingly. – OrangeDog – 2019-05-20T12:24:12.147
Apple were late to the *nix party. I don't know that I'd use their doco as gospel. – mcalex – 2019-05-21T03:50:25.397
sudo whoami
appears reasonably conclusive – jymbob – 2019-05-21T11:52:19.9631@jymbob -
sudo -u someotheruser whoami
similarly shows that whileroot
is the default target, the tool is more generic than that. – David Spillett – 2019-05-21T15:07:33.697@DavidSpillett granted, but the OP asks "when I do
sudo node my_node_program
[am I] running the program as the root user" so my suggestion was that running a command which print which user just ran the command usingsudo
is (in that instance) fairly conclusive.su
also defaults to root, but that wasn't part of the question, so I didn't include it. – jymbob – 2019-05-22T21:20:53.180