Definition
sudo (superuser do) is a program that lets an allowed user run specific commands as another user—almost always root—after re-authenticating (unless configured otherwise). It consults /etc/sudoers and optional snippets under /etc/sudoers.d/ to decide who may run what, from which host, and whether a password is required.
How it differs from su
su - starts a full root shell if you know the root password. sudo keeps root locked or unknown while delegating least privilege: grant systemctl restart nginx without granting disk wipe tools. Every sudo invocation can be logged with the real username, aiding audits.
Mechanics you will hit
| Invocation | Effect | Caution |
|---|---|---|
sudo command | Run one command as root | Shell redirections may run as your user unless grouped carefully |
sudo -i | Simulate root login shell | Broad power—use sparingly |
sudo -u www-data cmd | Drop to another user | Still subject to sudoers rules |
sudo -l | List allowed commands | Great first step on unfamiliar systems |
Editing policy safely
Never edit /etc/sudoers with a normal editor without locking—use visudo (or visudo -f /etc/sudoers.d/custom) so syntax is validated before save. A broken sudoers file can lock everyone out of privilege elevation.
Security mindset
NOPASSWD is convenient and risky on workstations with untrusted code. Combine sudo with SSH keys + MFA, central logging, and minimal PATH inside privileged scripts.
Related: Linux commands primer, What chmod 777 means, Linux user and permission commands, Linux security commands.