Linux Fundamentals · 3.3
🔑 sudo, Root & User Context
The key to administrative power — and the responsibility that comes with it⏱ ~2 min
In Linux, administrative tasks require root-level permissions. Unlike Windows where you log in as Administrator, Linux keeps the root account separate and uses sudo to grant temporary elevated privileges.
Three Ways to Run Commands as Root
| Method | Command | When to Use |
|---|---|---|
| sudo | sudo adduser alice | Single command — elevates just that one command |
| sudo su | sudo su | Switch to root shell — all following commands run as root (exit to return) |
| su root | su root (requires root password) | Rarely used in Ubuntu — use sudo su instead |
bash
# Run a single command as rootsudo apt update # Switch to root shell (stays root until you type exit)sudo suwhoami # confirms: rootexit # return to normal user # Check who you currently arewhoamiid # shows UID, GID, and all groups # Who's currently logged in?whow # more details including what they're doing🔒 SecurityRunning everything as root is dangerous. If you're root and accidentally type 'rm -rf /' you destroy the entire system with no prompt. Best practice: run as a normal user and only use sudo when needed. This is called 'principle of least privilege'.
The sudo Configuration File: /etc/sudoers
- •Controls who is allowed to use sudo and what they can run
- •Never edit this with a regular text editor — use
sudo visudowhich validates syntax before saving - •Corrupted /etc/sudoers can lock everyone out of sudo permanently
- •Competition: check /etc/sudoers for unauthorized users with ALL=(ALL) NOPASSWD: ALL — that gives passwordless sudo to anyone
🧠Quick Checkfirst try = +5 XP
What does sudo do?
🎮 Practice what you learned
⭐ 0 XP🔥 0 days