Sudo and Root
sudo runs one command as the root user. The root user is the superuser, and the superuser can change anything.
Who is running now
whoami prints the name of the user who runs it.
$ whoamiA plain read is refused
The secret file belongs to the root user. The plain read is refused.
$ cat /root/secret.txtThe same read with sudo
sudo runs the read as the root user. The secret line appears.
$ sudo cat /root/secret.txtExample
$ whoami
$ sudo whoamiKey points
- sudo lends one command the power of the root user.
- Use sudo before a command to run that command as the root user.
- A password is a secret word that proves who you are.
- On most machines, sudo asks for a password before it runs the command.
- The secret file belongs to the root user, so a plain read fails.
In this example, whoami prints alex. sudo whoami prints root. The same name check gives two answers, one for alex and one for the root user.
Note
The practice user alex runs sudo without a password.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
What does sudo do?