sudo
system administrationLinux/Unix
The sudo command is one of the most frequently used commands in Linux/Unix-like operating systems. sudo Execute a command as another user
Quick Reference
Command Name:
sudo
Category:
system administration
Platform:
Linux/Unix
Basic Usage:
sudo [options] [arguments]
Common Use Cases
Syntax
sudo [options] [command]
Options
Option | Description |
---|---|
-A, --askpass |
Use a helper program for password prompting |
-b, --background |
Run command in the background |
-C, --close-from=num |
Close all file descriptors >= num |
-E, --preserve-env |
Preserve user environment when running command |
--preserve-env=list |
Preserve specific environment variables |
-e, --edit |
Edit files instead of running a command |
-g, --group=group |
Run command as the specified group name or ID |
-H, --set-home |
Set HOME variable to target user's home dir |
-h, --help |
Display help message and exit |
-h, --host=host |
Run command on host (if supported by plugin) |
-i, --login |
Run login shell as the target user; a login shell resets most environment variables |
-K, --remove-timestamp |
Remove timestamp file completely |
-k, --reset-timestamp |
Invalidate timestamp file |
-l, --list |
List user's privileges or check a specific command |
-n, --non-interactive |
Non-interactive mode, no prompts are used |
-P, --preserve-groups |
Preserve group vector instead of setting to target's |
-p, --prompt=prompt |
Use the specified password prompt |
-r, --role=role |
Create SELinux security context with specified role |
-S, --stdin |
Read password from standard input |
-s, --shell |
Run shell as the target user; a non-login shell |
-t, --type=type |
Create SELinux security context with specified type |
-T, --command-timeout=timeout |
Terminate command after the specified time limit |
-U, --other-user=user |
In list mode, display privileges for user |
-u, --user=user |
Run command (or edit file) as specified user name or ID |
-V, --version |
Display version information and exit |
-v, --validate |
Update user's timestamp without running a command |
Examples
How to Use These Examples
The examples below show common ways to use the sudo
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
sudo apt update