root is the administrator account of a Linux system. It has UID 0 and passes almost all permission checks: it can read other people's files, install software, stop any process and delete the system itself.
Why not stay logged in as root
A typo as an ordinary user usually damages only your own files. The same typo as root can wipe the machine. Programs you run also inherit root's power. So the habit is: work as yourself, and raise privileges only for the command that needs them.
Even root has limits. A read-only filesystem still refuses writes.
sudo
sudo runs one command with another user's privileges, root by default:
$ cat /etc/shadow
cat: /etc/shadow: Permission denied
$ sudo cat /etc/shadow
[sudo] password for maya:
root:*:19800:0:99999:7:::
...It usually asks for your password, not root's, and records the command in the system log. Who may use it is set in /etc/sudoers and /etc/sudoers.d/. Edit these with visudo, which checks the syntax so a mistake does not lock you out.
Commonly, members of the sudo group (Debian, Ubuntu) are allowed. Other distributions often use wheel. See what you may run with sudo -l.
Redirection is done by your own shell before sudo starts, so sudo echo x > /etc/motd fails. Use echo x | sudo tee /etc/motd instead, which overwrites the file.
su and root shells
su switches to another user and asks for that user's password:
$ su -
Password:
# whoami
root
# exitThe - gives a full login environment. The # prompt is your warning that you are root. sudo -i gives a similar shell using your sudo rights.
Ubuntu locks the root password by default, so su - does not work there until one is set. Use sudo instead. Debian and others depend on choices made at installation.
Try it
$ whoami
$ sudo whoami
$ sudo -l
$ id rootIf you do not have sudo rights, read the message and do not try to get around it: ask the administrator.
Check your understanding
root
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.