2014-06-26 14:12:56 +01:00
|
|
|
# sudo
|
|
|
|
|
2018-10-22 18:20:30 +01:00
|
|
|
> Executes a single command as the superuser or another user.
|
2021-01-30 21:04:40 +00:00
|
|
|
> More information: <https://www.sudo.ws/sudo.html>.
|
2014-06-26 14:12:56 +01:00
|
|
|
|
2018-10-22 18:20:30 +01:00
|
|
|
- Run a command as the superuser:
|
2014-06-26 14:12:56 +01:00
|
|
|
|
2018-10-23 19:18:36 +01:00
|
|
|
`sudo {{less /var/log/syslog}}`
|
2014-06-26 14:12:56 +01:00
|
|
|
|
2018-10-22 18:20:30 +01:00
|
|
|
- Edit a file as the superuser with your default editor:
|
2014-06-26 14:12:56 +01:00
|
|
|
|
2021-01-30 21:04:40 +00:00
|
|
|
`sudo --edit {{/etc/fstab}}`
|
2014-06-26 14:12:56 +01:00
|
|
|
|
2018-10-22 18:20:30 +01:00
|
|
|
- Run a command as another user and/or group:
|
2014-06-26 14:12:56 +01:00
|
|
|
|
2021-01-30 21:04:40 +00:00
|
|
|
`sudo --user={{user}} --group={{group}} {{id -a}}`
|
2014-06-26 14:12:56 +01:00
|
|
|
|
2024-03-10 06:53:17 +00:00
|
|
|
- Repeat the last command prefixed with `sudo` (only in Bash, Zsh, etc.):
|
2014-06-26 14:12:56 +01:00
|
|
|
|
2017-09-20 22:45:15 +01:00
|
|
|
`sudo !!`
|
2017-11-27 06:48:29 +00:00
|
|
|
|
2021-01-30 21:04:40 +00:00
|
|
|
- Launch the default shell with superuser privileges and run login-specific files (`.profile`, `.bash_profile`, etc.):
|
2017-11-27 06:48:29 +00:00
|
|
|
|
2021-01-30 21:04:40 +00:00
|
|
|
`sudo --login`
|
|
|
|
|
|
|
|
- Launch the default shell with superuser privileges without changing the environment:
|
|
|
|
|
|
|
|
`sudo --shell`
|
|
|
|
|
|
|
|
- Launch the default shell as the specified user, loading the user's environment and reading login-specific files (`.profile`, `.bash_profile`, etc.):
|
|
|
|
|
|
|
|
`sudo --login --user={{user}}`
|
|
|
|
|
|
|
|
- List the allowed (and forbidden) commands for the invoking user:
|
|
|
|
|
|
|
|
`sudo --list`
|