When to use sudo
Use sudo to perform an allowed operation as another account. Prefer a specific command and target user to an unrestricted root shell, and check policy before automating privileged administration.
Syntax
sudo [PARAMETERS] COMMAND [ARGUMENTS...]Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.
Common options and arguments
Usage examples
Check permissions
sudo -lThe policy lists commands the current account is permitted to run, possibly after authentication.
Run check from deploy
sudo -u deploy idThe identity command runs as the named deployment user.
Read service status
sudo systemctl status nginxService status is queried with elevated privileges if local policy authorizes it.
Notes and limitations
- Access is determined by policy sudoers; sudo does not make an arbitrary command safe.
- The password is entered interactively. After administrative actions, if necessary, run sudo -k.
Common questions and troubleshooting
Why does sudo report that a command is not allowed?
The configured policy may restrict commands, arguments or target users. Ask the administrator to grant the needed operation rather than bypassing policy.
Does sudo affect every command in a pipeline?
No. It applies to the command it launches. Other pipeline stages and shell redirections run with their own privileges.
Further help
Options vary by version and distribution. Check the installed documentation with this command: man sudo.