ipdetecto.com logo
ipdetecto.com
My IPSpeed
Knowledge Hub
HomeKnowledge HubWhat Does Sudo Do Linux
© 2026 ipdetecto.com
support@ipdetecto.comAboutContactPrivacyTermsllms.txt
Basics
5 MIN READ
Apr 19, 2026

What Does sudo Do in Linux?

sudo runs a single command with elevated privileges using a policy file (/etc/sudoers): authentication, timestamp tickets, user and command allowlists, logging to syslog, and why sudo is preferred over shared root passwords.

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

InvocationEffectCaution
sudo commandRun one command as rootShell redirections may run as your user unless grouped carefully
sudo -iSimulate root login shellBroad power—use sparingly
sudo -u www-data cmdDrop to another userStill subject to sudoers rules
sudo -lList allowed commandsGreat 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.

Frequently Asked Questions

Q.Why does sudo ask for my password, not root's?

sudo authenticates you to prove physical presence, then checks sudoers to see if your account may run the requested command as root. You typically do not need the root password.

Q.What is the sudo timestamp ticket?

After a successful password, sudo may cache authentication for a few minutes (timestamp_timeout) so repeated sudo commands do not re-prompt. Clear with sudo -k or wait for timeout.

Q.What does sudoers NOPASSWD mean?

The listed user or group may run the matching command(s) without typing a password—convenient for automation but dangerous if malware can invoke those binaries.

Q.Is sudo a security boundary?

It is policy enforcement on top of the kernel, not magic. Misconfigured sudoers (editors, wildcards, shell escapes) can allow privilege escalation—treat reviews as seriously as firewall rules.

Q.Why did my command fail inside sudo?

Environment differences: PATH, HOME, and shell builtins may differ. Use full paths for scripts, or sudo -H / sudo -E deliberately when you understand the implications.

Q.How is doas different from sudo?

OpenBSD's doas is a smaller alternative with simpler configuration. Many Linux systems still standardize on sudo and sudoers.d snippets.

Q.Should I disable the root account?

Many distros ship without a known root password and expect sudo. Ensure at least one user can sudo before locking root, and keep recovery console access documented.

Q.Where are sudo attempts logged?

Typically syslog (auth.log, secure, or journald) with lines containing sudo: and the invoking user—ship these logs to your SIEM for tamper-resistant auditing.
TOPICS & TAGS
what does sudo dosudoersvisudosudo vs suLinux privilege escalationNOPASSWDsudo -i