sudo - execute a command as another user
sudo [-u user] [-i] [-s] [-k] [-l] command [args]
Options you will use
-u user- Run the command as user instead of root.
-i- Run a login shell as the target user (fresh environment, target user HOME).
-s- Run a shell as the target user, keeping most of the current environment.
-k- Invalidate the cached credentials; the next sudo asks for a password again.
-l- List the commands the invoking user is allowed to run.
-v- Refresh the cached credentials (asks for the password if needed) without running a command.
Examples
$ sudo systemctl restart nginxrun one privileged command
$ sudo !!re-run the previous command with sudo
$ echo "x" | sudo tee /etc/foowrite to a root-owned file (redirection would NOT work)
Gotchas
sudo echo hi > /etc/foofails: the shell opens the redirection as YOU, before sudo ever runs. Use| sudo teeorsudo sh -c '...'.- Credentials are cached for 15 minutes per terminal.
Taught in
Try sudo in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.