Commands · Command

CommandLinuxmacOS

sudo

sudo command

Runs a single command with elevated (typically root) privileges, prompting for the current user's own password rather than root's — the preferred alternative to logging in as root directly.

// FLAGS

-urun as a specific user instead of root
-istart an interactive root login shell
-llist what commands the current user is permitted to run with sudo

// EXAMPLE

sudo systemctl restart nginx — restarts the nginx service with root privileges, without ever fully switching users.

// GOTCHA

sudo caches the password for a few minutes by default, so a script run right after an interactive sudo command might not prompt again — this can be surprising in automation, where every privileged step is expected to need explicit authorization.

// RELATED COMMANDS