| | |

LFCA 23 ๐Ÿง The Root User and sudo

Every Linux system has a superuser. UID 0 โ€” root โ€” is the account with no restrictions. It can read any file, write any file, kill any process, mount any filesystem, and change any permission. The kernel treats UID 0 as exempt from the checks that apply to every other user. This power is necessary: someone has to install software, configure the network, and manage user accounts. But it is also the single greatest risk on the system. A mistake made as root is not caught by the kernel โ€” there is no permission check to fail, no error to stop it. The command runs exactly as written, even if it is destructive. The modern answer to this problem is sudo, a tool that grants specific users the ability to run specific commands with root’s privileges, without ever giving them root’s password and without requiring them to log in as root. This chapter covers what root is, why direct root login is discouraged, how sudo works, the sudoers file that defines its rules, and the habits that keep administrative access safe.

Key point: The root user has UID 0 and is exempt from most permission checks. Logging in as root or switching to root with su grants unrestricted access with no audit trail of who did what. sudo solves both problems: it grants elevated privileges for specific commands, it authenticates the user with their own password rather than root’s, and it logs every command that runs through it. The rules live in /etc/sudoers, which should only be edited with visudo to prevent syntax errors that could lock everyone out.


What root is, and why direct login is dangerous

Root is not a normal user with extra permissions. It is the account the kernel treats specially. When a process runs with effective UID 0, the kernel skips the permission checks that would otherwise apply. File permissions become advisory โ€” root can read a file with mode 000 and write to a file owned by another user. This is by design: someone has to be able to repair the system when permissions are wrong or files are corrupted.

Why this makes root dangerous. The same exemption that lets root repair a broken system lets root destroy a working one. There is no safety net. rm -rf / runs because the kernel does not stop it. A mistyped path in a configuration command takes effect immediately. The system does not ask “are you sure?” because root is assumed to know what it is doing. The assumption is frequently wrong โ€” every experienced administrator has a story about a command run as root that did something unintended.

Why logging in as root is discouraged. When you log in as root directly, every command you type runs as root. There is no separation between the ordinary work of navigating files and the administrative work of changing them. The danger is not that you will run a destructive command on purpose; it is that you will run an ordinary command in the wrong directory or with the wrong argument, and root will execute it without complaint. Running as a normal user and elevating only when needed creates a natural pause: the sudo prefix is a conscious decision to use root’s power.

Why su is better than direct login but still not ideal. su switches your identity to root after entering root’s password. It is better than logging in as root because you can start as yourself, but it has two problems. First, it requires sharing root’s password among everyone who needs administrative access. If one person leaves the organization, the password must be changed for everyone. Second, it provides no audit trail. Once you su to root, every command runs as root, and the system logs show only that a shell was opened as root โ€” not who opened it or what they did. The sudo approach solves both problems .


How sudo works

sudo stands for “superuser do.” It allows a permitted user to run a command as another user, typically root, without knowing that user’s password. The user authenticates with their own password, and sudo checks a configuration file called /etc/sudoers to determine whether the command is allowed .

The flow is straightforward. You type sudo followed by the command you want to run as root. sudo prompts for your password โ€” not root’s. It then consults /etc/sudoers to see whether you are permitted to run that command. If you are, the command executes with root’s privileges. If not, sudo prints an error and the command does not run .

Why authentication uses the invoking user’s password. This is the core security improvement over su. Each administrator has their own password, and no one needs to know root’s password except the person who set it during installation. When an administrator leaves, their account is disabled, and their ability to use sudo disappears with it. There is no shared secret to rotate. The system knows exactly which human account made each sudo request .

Why sudo caches credentials. After the first successful authentication, sudo remembers that you authenticated for a short period โ€” typically 15 minutes โ€” so you do not have to type your password for every command . This cache is per-terminal by default, so authenticating in one terminal does not grant passwordless sudo in another . The cache is stored in a timestamp file, and sudo -k clears it immediately, forcing re-authentication . The timeout is configurable through timestamp_timeout in the sudoers file.

Why every command is logged. sudo records the command, the arguments, the user who invoked it, and the time it ran. The default log destination is the system log, but sudoers can be configured to write to a dedicated file with Defaults logfile="/var/log/sudo.log" . This audit trail is the second major improvement over su. If something goes wrong, the log shows who ran what. If someone misuses their privileges, the evidence is there .

Why sudo restricts what can be run. Unlike su, which grants full root access once authenticated, sudo can be configured to allow only specific commands. A developer might be permitted to restart the web server but not to modify user accounts. An operator might be allowed to manage backups but not to install packages. This is the principle of least privilege applied to administrative access: grant only what is needed, nothing more .


The sudoers file

The rules that govern sudo live in /etc/sudoers. The file is plain text, and its syntax is precise. Each rule grants a user or group permission to run certain commands on certain hosts as certain users.

The basic rule format is:

user  host=(runas) command

The user is the username or a %group. The host is the hostname where the rule applies (ALL for any host). The runas is the user the command runs as (root or ALL). The command is the absolute path to the executable, with ALL for any command .

A simple example: alice ALL=(ALL) ALL grants Alice permission to run any command as any user on any host. The common configuration for an administrator group is %wheel ALL=(ALL) ALL, which grants every member of the wheel group full sudo access .

Why visudo is mandatory. /etc/sudoers cannot be edited with a normal text editor. A syntax error in the file can break sudo entirely, leaving no way to run administrative commands. visudo opens the file in an editor, and when you save, it validates the syntax before writing. If the syntax is wrong, it warns you and lets you fix it or discard the changes . This is the single most important habit for anyone who configures sudo.

Why /etc/sudoers.d/ exists. Adding rules directly to /etc/sudoers mixes custom configuration with the distribution’s defaults. The #includedir /etc/sudoers.d directive tells sudo to read additional files from that directory, and this is where custom rules belong . Each file can be created with visudo -f /etc/sudoers.d/filename, which gives the same syntax checking as editing the main file. This keeps the configuration modular and makes it easier to review and remove individual rules.

Why file naming and ordering matter. Files in /etc/sudoers.d/ are read in alphabetical order. Prefixing filenames with numbers โ€” 01_users, 10_services, 50_admins โ€” makes the order explicit . If two files contain conflicting rules, the later one wins. Numbering makes the intended precedence visible.

Why the %wheel group is the common target. On most distributions, the wheel group is the traditional administrative group. Granting sudo to %wheel instead of to individual users means that adding or removing administrative access is a group membership change, not a sudoers edit. The rule stays stable, and the membership is managed separately .


Practical sudo configuration

The default configuration on most systems allows members of the sudo or wheel group to run any command. That is a reasonable starting point for a small team where every administrator is trusted equally. For larger environments, more granular rules are the norm.

A rule that allows a user to restart the web server without granting full root access looks like this:

webadmin ALL=(root) /usr/bin/systemctl restart nginx

The user webadmin can run that one command as root. Attempting to run anything else with sudo produces a “not allowed” error. This is the principle of least privilege in practice .

A rule that allows a group to manage users without full root:

%useradmins ALL=(root) /usr/sbin/useradd, /usr/sbin/userdel, /usr/sbin/usermod

The members of useradmins can add, remove, and modify users, but cannot install packages, edit network configuration, or run arbitrary commands.

Why command paths must be absolute. sudoers requires the full path to each executable. A rule with useradd instead of /usr/sbin/useradd is a syntax error. The path pins the rule to a specific binary, which prevents a user from creating a script with the same name in their PATH and getting it executed as root .

Why passwordless sudo is sometimes configured. A rule with NOPASSWD: before the command list allows that user to run the listed commands without entering a password:

backup ALL=(root) NOPASSWD: /usr/local/bin/backup.sh

This is used for automation โ€” a scheduled backup job should not block waiting for a password prompt. It is also used for commands that are considered safe enough that the authentication step adds no security. The risk is real: if the account is compromised, the attacker can run those commands without knowing the password. Passwordless sudo should be limited to commands that cannot be abused to gain a shell or read sensitive files .

Why sudo -i and sudo su are different from sudo command. Running sudo command executes one command with elevated privileges and returns to your normal user. Running sudo -i starts a root login shell โ€” you are now root for the rest of the session, and every command runs as root until you exit. This is sometimes necessary for a sequence of administrative tasks, but it reintroduces the problem that sudo was designed to solve: the safety pause is gone, and every command runs as root without the sudo prefix. Use sudo -i sparingly and exit promptly .


Complete Example Session

# ============================================
# PART 1: CHECK YOUR CURRENT IDENTITY
# ============================================

whoami
# alice

id
# uid=1000(alice) gid=1000(alice) groups=1000(alice),27(sudo)

# ============================================
# PART 2: RUN A COMMAND WITH SUDO
# ============================================

sudo whoami
# [sudo] password for alice:
# root

# The command ran as root, but you authenticated as alice

# ============================================
# PART 3: SUDO CREDENTIAL CACHE
# ============================================

sudo whoami
# root
# (no password prompt โ€” cached for 15 minutes)

sudo -k
# (clears the cache)

sudo whoami
# [sudo] password for alice:
# root
# (password required again)

# ============================================
# PART 4: VIEW SUDO LOGS
# ============================================

sudo journalctl -u sudo | tail -5
# (shows recent sudo invocations)
# alice : TTY=pts/0 ; PWD=/home/alice ; USER=root ;
#   COMMAND=/usr/bin/whoami

# ============================================
# PART 5: EDIT SUDOERS SAFELY
# ============================================

sudo visudo
# (opens /etc/sudoers in an editor)
# (on exit, syntax is validated)

# ============================================
# PART 6: CREATE A CUSTOM RULE
# ============================================

sudo visudo -f /etc/sudoers.d/10_webadmin
# (creates a new file with syntax checking)

# Inside the file:
# webadmin ALL=(root) /usr/bin/systemctl restart nginx

# ============================================
# PART 7: TEST THE RULE
# ============================================

su - webadmin
# (switch to the webadmin user)

sudo systemctl restart nginx
# [sudo] password for webadmin:
# (command runs successfully)

sudo cat /etc/shadow
# Sorry, user webadmin is not allowed to execute
#   '/usr/bin/cat /etc/shadow' as root.
# (denied โ€” the rule only permits systemctl restart nginx)

# ============================================
# PART 8: SU VS SUDO
# ============================================

su -
# Password:
# (enters root's password โ€” you are now root)
# (every command runs as root; no per-command logging)

exit

# ============================================
# PART 9: GROUP-BASED SUDO
# ============================================

# Add alice to the wheel group
sudo usermod -aG wheel alice

# The rule in /etc/sudoers:
# %wheel ALL=(ALL) ALL

# ============================================
# PART 10: DISABLE ROOT SSH LOGIN
# ============================================

sudo grep PermitRootLogin /etc/ssh/sshd_config
# PermitRootLogin no

# ============================================
# PART 11: SECURITY AUDIT
# ============================================

# Who has sudo access?
sudo grep -E '^[^#].*ALL' /etc/sudoers /etc/sudoers.d/*
# (shows all active rules)

# Check sudo log
sudo journalctl -u sudo --since "1 hour ago" | tail -20

Each part covers one aspect of sudo usage. Parts 1 through 4 show the basic flow. Parts 5 through 7 show configuration. Parts 8 through 11 show the comparison with su, group-based access, SSH hardening, and auditing.


Quick Reference

Identity and Elevation

CommandWhat It Does
whoamiCurrent username
idCurrent UID, GID, groups
sudo commandRun one command as root
sudo -iStart a root login shell
su -Switch to root (needs root password)
su - userSwitch to another user

sudo Options

OptionEffect
sudo -kClear cached credentials
sudo -lList allowed commands
sudo -vRefresh cached credentials
sudo -u userRun as another user
sudo -iRoot login shell
sudo -sRoot shell (no login)

sudoers Rule Format

PartExampleMeaning
Useralice or %wheelWho the rule applies to
HostALLWhere it applies
Runas(root) or (ALL)What user to run as
Command/usr/bin/systemctlAbsolute path

sudoers File Locations

LocationPurpose
/etc/sudoersMain configuration
/etc/sudoers.d/Custom rule files
/var/log/sudo.logOptional dedicated log

su vs sudo

Aspectsusudo
PasswordTarget user’sYour own
ScopeFull identity switchPer-command (default)
AuditMinimalPer-command logging
GranularityAll or nothingCommand-by-command
Root password sharedYesNo

Security Hardening

MeasurePurpose
PermitRootLogin noDisable SSH as root
%wheel groupGroup-based sudo
visudo onlyPrevent syntax errors
timestamp_timeout=5Shorter credential cache
NOPASSWD limitedOnly for safe automation
Log sudo commandsAudit trail

Best Practices

โœ… Do This:

# Always use visudo for sudoers changes
sudo visudo                                                    # โœ…

# Use /etc/sudoers.d/ for custom rules
sudo visudo -f /etc/sudoers.d/10_webadmin                     # โœ…

# Grant sudo to groups, not individuals
%wheel ALL=(ALL) ALL                                          # โœ…

# Use the most specific command paths
webadmin ALL=(root) /usr/bin/systemctl restart nginx          # โœ…

# Clear credentials when stepping away
sudo -k                                                       # โœ…

# Disable direct root SSH login
PermitRootLogin no                                            # โœ…

# Check sudo access with sudo -l
sudo -l                                                       # โœ…

โŒ Don’t Do This:

# Don't edit /etc/sudoers directly
vim /etc/sudoers  # syntax error locks you out             # โš ๏ธ

# Don't share root's password
# Use sudo with individual accounts                        # โš ๏ธ

# Don't grant NOPASSWD to dangerous commands
backup ALL=(root) NOPASSWD: /bin/bash  # shell access     # โš ๏ธ

# Don't use su - when sudo works
su -  # requires root password, no per-command audit      # โš ๏ธ

# Don't leave a root shell open
sudo -i  # exit when done                                 # โš ๏ธ

# Don't log in as root directly
# Use your own account and sudo                            # โš ๏ธ

Common Pitfalls

PitfallProblemSolution
Editing sudoers with vimSyntax error locks out sudoUse visudo
Forgetting absolute pathsRule rejected or ineffectiveFull path to executable
Using su instead of sudoNo audit trail, shared passwordPrefer sudo
NOPASSWD on shell commandsPasswordless root shellLimit to safe commands
Not checking sudo -lUnsure of permissionsRun sudo -l
Credential cache on shared terminalAnother user inherits sudoUse sudo -k after use
Granting ALL=(ALL) ALL by defaultOver-privileged usersGrant specific commands
Leaving root shell openFull root access unattendedExit when done

Real-World Examples

1. Check what you can run with sudo

sudo -l

2. Run a single command as root

sudo systemctl restart nginx

3. Open a root shell for a sequence

sudo -i

4. Clear cached credentials

sudo -k

5. Create a granular rule

sudo visudo -f /etc/sudoers.d/10_webadmin

6. Grant sudo to a group

%wheel ALL=(ALL) ALL

7. Allow a specific command without password

backup ALL=(root) NOPASSWD: /usr/local/bin/backup.sh

8. Disable root SSH login

sudo sed -i 's/^#*PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config

9. Check who has sudo access

sudo grep -E '^[^#]' /etc/sudoers /etc/sudoers.d/*

10. View sudo audit log

sudo journalctl -u sudo --since "1 hour ago"

Visual: su vs sudo

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  su -                                                    โ”‚
โ”‚                                                          โ”‚
โ”‚  You type: su -                                           โ”‚
โ”‚  Password: <ROOT PASSWORD>                                โ”‚
โ”‚       โ”‚                                                  โ”‚
โ”‚       โ–ผ                                                  โ”‚
โ”‚  You are root. Every command runs as root.               โ”‚
โ”‚  No per-command logging. One shared secret.              โ”‚
โ”‚                                                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  sudo command                                            โ”‚
โ”‚                                                          โ”‚
โ”‚  You type: sudo systemctl restart nginx                   โ”‚
โ”‚  Password: <YOUR PASSWORD>                                โ”‚
โ”‚       โ”‚                                                  โ”‚
โ”‚       โ–ผ                                                  โ”‚
โ”‚  sudo checks /etc/sudoers.                               โ”‚
โ”‚       โ”‚                                                  โ”‚
โ”‚       โ”œโ”€โ”€ Allowed โ”€โ”€โ–บ command runs as root               โ”‚
โ”‚       โ”‚              (logged: who, what, when)           โ”‚
โ”‚       โ”‚                                                  โ”‚
โ”‚       โ””โ”€โ”€ Denied โ”€โ”€โ–บ error, command does not run         โ”‚
โ”‚                                                          โ”‚
โ”‚  You return to your normal user after the command.        โ”‚
โ”‚                                                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: sudoers Rule Anatomy

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  %wheel  ALL  =  (ALL)  ALL                              โ”‚
โ”‚    โ”‚      โ”‚        โ”‚     โ”‚                               โ”‚
โ”‚    โ”‚      โ”‚        โ”‚     โ””โ”€โ”€ Command: ALL commands       โ”‚
โ”‚    โ”‚      โ”‚        โ””โ”€โ”€ Runas: as ANY user                โ”‚
โ”‚    โ”‚      โ””โ”€โ”€ Host: on ANY host                          โ”‚
โ”‚    โ””โ”€โ”€ User: % group "wheel"                             โ”‚
โ”‚                                                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  webadmin  ALL  =  (root)  /usr/bin/systemctl restart nginxโ”‚
โ”‚    โ”‚         โ”‚        โ”‚         โ”‚                        โ”‚
โ”‚    โ”‚         โ”‚        โ”‚         โ””โ”€โ”€ ONE specific command โ”‚
โ”‚    โ”‚         โ”‚        โ””โ”€โ”€ Runas: ONLY as root            โ”‚
โ”‚    โ”‚         โ””โ”€โ”€ Host: ANY                               โ”‚
โ”‚    โ””โ”€โ”€ User: webadmin (individual)                       โ”‚
โ”‚                                                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: sudo Credential Cache

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  sudo whoami                                             โ”‚
โ”‚  [sudo] password for alice: ******                       โ”‚
โ”‚  root                                                    โ”‚
โ”‚       โ”‚                                                  โ”‚
โ”‚       โ–ผ                                                  โ”‚
โ”‚  Timestamp written to /var/run/sudo/ts/alice            โ”‚
โ”‚       โ”‚                                                  โ”‚
โ”‚       โ–ผ                                                  โ”‚
โ”‚  sudo apt update                                         โ”‚
โ”‚  (no password โ€” cached)                                  โ”‚
โ”‚       โ”‚                                                  โ”‚
โ”‚       โ–ผ                                                  โ”‚
โ”‚  ... 15 minutes pass ...                                 โ”‚
โ”‚       โ”‚                                                  โ”‚
โ”‚       โ–ผ                                                  โ”‚
โ”‚  sudo whoami                                             โ”‚
โ”‚  [sudo] password for alice:                              โ”‚
โ”‚  (cache expired โ€” password required)                     โ”‚
โ”‚                                                          โ”‚
โ”‚  sudo -k clears the cache immediately.                   โ”‚
โ”‚                                                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: Where sudoers Rules Live

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  /etc/sudoers (main file โ€” edit with visudo)             โ”‚
โ”‚    โ”‚                                                     โ”‚
โ”‚    โ”‚  #includedir /etc/sudoers.d                         โ”‚
โ”‚    โ”‚         โ”‚                                           โ”‚
โ”‚    โ–ผ         โ–ผ                                           โ”‚
โ”‚  /etc/sudoers.d/                                         โ”‚
โ”‚    โ”œโ”€โ”€ 01_users          (read first)                    โ”‚
โ”‚    โ”œโ”€โ”€ 10_webadmin       (read second)                   โ”‚
โ”‚    โ”œโ”€โ”€ 50_admins         (read third)                    โ”‚
โ”‚    โ””โ”€โ”€ 99_local          (read last โ€” wins conflicts)    โ”‚
โ”‚                                                          โ”‚
โ”‚  Files are read alphabetically.                          โ”‚
โ”‚  Later files override earlier ones.                      โ”‚
โ”‚  Numbering makes the order explicit.                     โ”‚
โ”‚                                                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: The Safety Pause

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  WITHOUT SUDO (logged in as root)                        โ”‚
โ”‚                                                          โ”‚
โ”‚  $ cd /etc                                              โ”‚
โ”‚  $ ls                                                   โ”‚
โ”‚  $ rm -rf nginx/                                        โ”‚
โ”‚       โ”‚                                                  โ”‚
โ”‚       โ””โ”€โ”€ Deleted immediately. No prompt.               โ”‚
โ”‚                                                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  WITH SUDO (logged in as normal user)                    โ”‚
โ”‚                                                          โ”‚
โ”‚  $ cd /etc                                              โ”‚
โ”‚  $ ls                                                   โ”‚
โ”‚  $ sudo rm -rf nginx/                                    โ”‚
โ”‚       โ”‚                                                  โ”‚
โ”‚       โ”œโ”€โ”€ [sudo] password for alice:                     โ”‚
โ”‚       โ”‚   (you pause, think, decide to proceed or not)   โ”‚
โ”‚       โ”‚                                                  โ”‚
โ”‚       โ””โ”€โ”€ If you proceed, it is logged.                 โ”‚
โ”‚                                                          โ”‚
โ”‚  The sudo prefix is a conscious decision.                โ”‚
โ”‚                                                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

ItemValue
Root UID0
Root privilegesExempt from permission checks
Direct root loginDiscouraged
su passwordTarget user’s (often root)
sudo passwordInvoking user’s
sudo cache duration15 minutes (default)
sudoers file/etc/sudoers
Custom rules/etc/sudoers.d/
Editorvisudo only
AuditPer-command logging

Key takeaways:

  • Root is UID 0 and is exempt from permission checks โ€” this is what makes it powerful and what makes it dangerous
  • Direct root login and su grant unrestricted access with minimal audit โ€” they are the old way, and they are discouraged
  • sudo authenticates with the invoking user’s password, not root’s, so no shared secret is needed
  • sudo logs every command it runs, creating an audit trail that su does not provide
  • sudo grants per-command privileges, not a full identity switch, which is the principle of least privilege in practice
  • The sudoers file defines the rules, and it must only be edited with visudo to prevent syntax errors that lock out administrative access
  • Custom rules belong in /etc/sudoers.d/, not in the main file, with numbered prefixes to control read order
  • sudo caches credentials for a short period โ€” 15 minutes by default โ€” so repeated commands do not require repeated passwords
  • NOPASSWD should be limited to safe automation commands โ€” granting it to a shell is equivalent to granting passwordless root
  • Disabling root SSH login and using sudo with individual accounts is the standard secure configuration for administrative access

Remember: The root account is necessary and dangerous in equal measure. sudo exists to give administrators the access they need without the risks of shared passwords, unrestricted sessions, and missing audit trails. The habit that matters most is the one sudo enforces: pausing before running a command as root, because the command will do exactly what it says. Configure sudoers with visudo, grant the narrowest privileges that get the job done, log everything, and never share root’s password.


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!