Root User and sudo
Level 2 · Files, users and permissions
Who the root user is and why it can change anything. How sudo runs one command as root, and why you should not log in as root at all.
Course contentsLesson 5 of 10
Level 1 · Typing commands
Level 2 · Files, users and permissions
Level 3 · Software and services
Level 4 · Timed jobs and the firewall
After this lesson you can
- Say what the root user may do
- Run one command with sudo
- Explain why daily work is done as a normal user
10 mincovers 2 glossary entries
Worth reading first: The Linux File Tree
Why you stop using root
The root user is the boss account on Linux. Its user number is 0, and it can read, change or delete any file on the machine. Normal users cannot touch system files. sudo lets a normal user run one command as root, after typing their own password. Day-to-day work is done as a normal user, with sudo only when needed.
Root is the way the system protects itself. A normal user can only harm their own files. A mistake made as root can wipe the whole machine. So can a bad program, if root starts it.
sudo goes in front of a command, such as sudo apt update. It asks for your own password, not root's. Only users on an allowed list may use it. Every command run this way is written to a log, so there is a record of who did what.
After you type your password, sudo trusts you for a few minutes, 15 by default on Ubuntu. Commands in that window do not ask again. Close the terminal, or wait, and it asks once more.
Many servers start with a root login only. The first job is to make a normal user, give it the right to use sudo, and log in as that user from then on. Logging in as root directly is then often switched off.
sudo also makes you slow down. Typing it is a small pause that says this command can break things. People who work as root all day lose that pause and make bigger mistakes.
A common mistake is to put sudo in front of a command that fails, just to make it work. When a command fails with permission denied in your own folder, the file is likely someone else's. Fix the owner. Do not run all your work as root from then on.
$ whoami
jack
$ sudo whoami
[sudo] password for jack:
rootWorked example
The words for this lesson2
Check yourself
Whose password does sudo ask for?
Finished this lesson?
Marking it complete also marks its 2 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.