Permissions

Linux sudo command

Run an approved command with elevated privileges. Check the command before confirming.

Availability: Common Linux commands; shell built-ins and external implementations may differ by distribution.中文

Syntax

sudo [OPTION]... COMMAND [ARGUMENT...]

Examples

Run a read-only service status check with elevated privileges.

sudo systemctl status ssh

Run id as the www-data account.

sudo -u www-data id

Parameters, options and clauses

Option / clauseDescription
-u USER, --user=USERRun the command as USER.
-g GROUP, --group=GROUPRun the command with GROUP as the primary group.
-i, --loginStart a login shell as the target user.
-s, --shellRun the configured shell as the target user.
-l, --listList allowed commands or privileges.
-kInvalidate cached credentials.
-vRefresh the credential timestamp without running a command.
Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory