Lesson 2.2 · Anatomy of a Running System
You have a running server. Now you need to understand what’s running on it and how to control it. This lesson covers the four things you’ll interact with constantly on every Linux system: systemd (which starts and manages services), the filesystem hierarchy (where things live), package management (installing and updating software), and users, groups, and sudo (who’s allowed to do what). These are the day-to-day fabric of operating a server.
systemd: the thing that runs everything
Section titled “systemd: the thing that runs everything”Recall from Lesson 1.1 that after the kernel boots, it starts one first process — PID 1 — which starts everything else. On modern Linux that’s systemd. It’s the init system and service manager: it starts your services at boot, keeps them running, restarts them if they crash, and collects their logs.
The core concept is a unit — systemd’s word for something it manages. The kind you’ll deal
with most is a service (a long-running program like a web server or SSH). You control units
with systemctl:
systemctl status ssh # is the SSH service running? show recent status and logssystemctl start nginx # start a service nowsystemctl stop nginx # stop it nowsystemctl restart nginx # restart it (e.g. after a config change)systemctl reload nginx # reload config without a full restart (if the service supports it)systemctl enable nginx # start it automatically at every bootsystemctl disable nginx # don't start it at bootsystemctl enable --now nginx # enable AND start in one stepThe distinction that trips up beginners: start vs enable. start runs a service right
now but doesn’t survive a reboot. enable makes it start at boot but doesn’t run it now.
You usually want both, which is why enable --now exists. “I restarted the service and it
worked, but after a reboot it’s gone” almost always means you started it but never enabled it.
Reading a service’s status
Section titled “Reading a service’s status”systemctl status ssh is one of the most useful commands you’ll run. It tells you:
- whether the service is active (running), inactive, or failed
- whether it’s enabled (starts at boot)
- the PID of the main process
- the last several log lines — often enough to see why something failed
When a service won’t start, systemctl status <name> is your first stop, and it usually points
you straight at the problem or tells you how to see more.
journalctl: the logs
Section titled “journalctl: the logs”systemd collects logs from all services into the journal. journalctl reads it:
journalctl -u ssh # all logs for the ssh unitjournalctl -u nginx -f # follow nginx's logs live (like tail -f)journalctl -xe # recent logs with extra detail — great after a failurejournalctl --since "10 min ago"journalctl -b # logs since the last bootjournalctl -p err # only error-priority messages and worseYou met tail -f on log files in Lesson 0.1; journalctl -u <service> -f is the systemd equivalent, and it’s how you’ll watch a service behave in real
time. This connects directly to Lesson 2.4 on reading logs.
The filesystem hierarchy: a map of where things live
Section titled “The filesystem hierarchy: a map of where things live”Linux organizes everything under / (from Lesson 0.1) into a
standard set of directories. Knowing this map means you know where to look for anything:
| Path | What lives here |
|---|---|
/etc |
Configuration files — system and service configs. You’ll edit here constantly. |
/var/log |
Log files (for services that don’t use the journal). |
/var |
Variable data — logs, caches, spool files, databases. |
/home/<user> |
Users’ home directories (your files). |
/root |
The root user’s home directory. |
/usr/bin, /bin |
Installed programs (executables). |
/usr/local |
Software you install manually (outside the package manager). |
/opt |
Optional/third-party software packages. |
/tmp |
Temporary files, wiped on reboot. |
/boot |
The kernel and bootloader files. |
/dev |
Device files (disks, etc. — you’ll meet these in Module 4). |
/proc, /sys |
Virtual filesystems exposing kernel and process info. |
The two you’ll touch most: /etc for configuration (every service you set up has its
config here) and /var/log plus the journal for logs. When someone says “check the
config,” they mean somewhere under /etc; “check the logs,” /var/log or journalctl.
Package management: installing software the right way
Section titled “Package management: installing software the right way”You don’t download software from random websites on a server. You use the package manager, which installs vetted software from Debian’s repositories, handles dependencies, and — crucially — lets you keep everything updated with one command. On Debian/Ubuntu the tool is apt:
sudo apt update # refresh the list of what's available and its versionssudo apt upgrade # install updates for everything installedsudo apt install htop # install a package (and its dependencies)sudo apt remove htop # remove a packagesudo apt search wireguard # find packagesapt list --installed # what's installedsudo apt autoremove # remove packages that were only there as dependencies and are no longer neededThe distinction to internalize: apt update refreshes the catalog; apt upgrade installs
the updates. You run update first (to learn what’s available), then upgrade (to apply
it). Running upgrade without a recent update upgrades against a stale catalog.
Users, groups, and sudo: who can do what
Section titled “Users, groups, and sudo: who can do what”Linux is multi-user at its core, and its permission model (which you met in Lesson 0.1) rests on users and groups. On a server this matters for both operation and security.
- Every user has a name and a numeric UID. root is UID 0 — the all-powerful administrator.
- Groups collect users so permissions can be granted to several people at once. A file or service can be owned by a group.
- Some users are system users that run services (e.g. a
www-datauser runs the web server) — not people, just identities with limited permissions, so a compromised service can’t do everything.
The least-privilege principle, in practice
Section titled “The least-privilege principle, in practice”You set this up during the install: root is locked, and your user runs privileged commands via sudo. This is the principle of least privilege — you operate as an ordinary user and only borrow root’s power for the specific commands that need it:
sudo apt install htop # run this one command as rootsudo systemctl restart nginxsudo -i # (occasionally) open a root shell — use sparinglyWhy not just log in as root and skip the sudo? Because:
- Every
sudois a deliberate pause — a moment to notice you’re about to do something privileged. Running as root all the time removes that guardrail, and a typo (rm -rfin the wrong place) has no safety net. sudouse is logged, giving you an audit trail of every privileged action.- If your everyday account is compromised, the attacker doesn’t automatically have root.
Managing users, for when you need to:
sudo adduser bob # create a new user (interactive, sets up home dir + password)sudo usermod -aG sudo bob # add bob to the "sudo" group (grant admin rights) — note -aGsudo deluser bob # remove a usergroups # what groups am I in?id bob # bob's UID, GID, and groupsThe -aG in usermod -aG matters: -a means append to the user’s groups. Forgetting -a
(just -G) replaces all their groups, which can accidentally remove someone from groups they
needed — a classic, painful mistake.
Putting it together
Section titled “Putting it together”You now have the operating vocabulary for any Linux server: systemd/systemctl to start,
stop, enable, and inspect services; journalctl to read their logs; the filesystem
hierarchy to know where configs (/etc) and logs (/var/log) live; apt to install and
patch software safely; and users, groups, and sudo to control who can do what under the
principle of least privilege. Everything you build in later modules — the reverse proxy, the
DNS resolver, the monitoring stack — is installed, configured, run, and debugged with exactly
these tools.
Quick self-check
Section titled “Quick self-check”- What’s the difference between
systemctl startandsystemctl enable? Which do you usually want? - A service worked after you started it, but it’s gone after a reboot. What did you forget?
- Where do configuration files live? Where do you look for logs?
- What’s the difference between
apt updateandapt upgrade, and in which order do you run them? - Explain the principle of least privilege and give two concrete reasons to use
sudoinstead of logging in as root. - Why does the
-amatter inusermod -aG sudo bob?