Toolkit: The Server Admin's Bench
The tools from this course in one place, with the job each one does, the command you will type most, and what to use when the default isn't there. Keep it next to your terminal.
Validate before you apply
| Daemon / file | Check command | Then apply with |
|---|---|---|
| systemd units | systemd-analyze verify unit.service (+ security --offline=true) |
systemctl daemon-reload and restart/reload |
| timers | systemd-analyze calendar --iterations=3 "…" |
systemctl enable --now x.timer |
| sshd | sshd -t, sshd -T (-C user=…,addr=… for Match blocks) |
systemctl reload ssh (keep a session open) |
| sudoers | visudo -c -s -f file |
move into /etc/sudoers.d/, mode 0440 |
| fstab | findmnt --verify |
systemctl daemon-reload, mount -a |
| nftables | nft -c -f file |
nft -f file (atomic) |
| nginx | nginx -t (nginx -T dumps the effective config) |
systemctl reload nginx |
| Caddy | caddy validate --config Caddyfile (caddy fmt, caddy adapt) |
systemctl reload caddy |
| HAProxy | haproxy -c -f haproxy.cfg |
systemctl reload haproxy |
| logrotate | logrotate -d /etc/logrotate.d/x |
the daily logrotate.timer |
| fail2ban | fail2ban-regex log filter, fail2ban-client -t |
systemctl reload fail2ban |
| shell scripts | shellcheck script.sh |
– |
Several of them in one pass, as a pre-deploy check might run them over a repository of server configs:
mkdir -p etc/ssh etc/sudoers.d etc/systemd/system
ssh-keygen -q -t ed25519 -N "" -f etc/ssh/hostkey
printf 'HostKey %s/etc/ssh/hostkey\nPermitRootLogin no\nPasswordAuthentication no\n' "$PWD" > etc/ssh/sshd_config
echo 'deploy ALL=(root) NOPASSWD: /usr/bin/systemctl restart app.service' > etc/sudoers.d/60-deploy
printf '[Service]\nExecStart=/usr/bin/python3 -m http.server 8000\nDynamicUser=yes\nRestart=on-failure\n' > etc/systemd/system/app.service
printf '#!/bin/bash\nfor f in $(ls *.log); do gzip $f; done\n' > cleanup.sh
check() { local name=$1; shift; if out=$("$@" 2>&1) && [ -z "$out" -o "$name" = sudoers ]; then echo "PASS $name"; else echo "FAIL $name"; echo "$out" | sed 's/^/ /' | head -4; fi; }
check sshd sshd -t -f etc/ssh/sshd_config
check sudoers visudo -c -s -f etc/sudoers.d/60-deploy
check unit systemd-analyze verify etc/systemd/system/app.service
check shellcheck shellcheck -f gcc cleanup.shPASS sshd
PASS sudoers
PASS unit
FAIL shellcheck
cleanup.sh:2:10: error: Iterating over ls output is fragile. Use globs. [SC2045]
cleanup.sh:2:15: note: Use ./*glob* or -- *glob* so names with dashes won't become options. [SC2035]
cleanup.sh:2:31: note: Double quote to prevent globbing and word splitting. [SC2086]
ShellCheck's three findings are the classics: never loop over ls output (use a glob), write globs as ./*.log so a file called -rf.log can't turn into an option, and quote variables (gzip "$f"), or a file name with a space becomes two arguments. The fixed line is for f in ./*.log; do gzip "$f"; done.
Inspecting a running server
| Question | First tool | Also |
|---|---|---|
| What runs, what failed? | systemctl --failed, systemctl status x |
systemctl list-timers, systemd-cgls |
| What did it log? | journalctl -u x -b -p warning |
journalctl -k (kernel), /var/log/* |
| Who is listening? | ss -tlnp |
ss -uanp, lsof -i :443 |
| Where does traffic go? | ip -br addr, ip route get <addr> |
ip -s link (errors/drops) |
| Does the name resolve? | getent hosts name (what apps see), dig name |
resolvectl status, dig +trace |
| Is the path OK? | mtr -rwzc 100 host |
traceroute -T -p 443, ping -M do -s 1472 |
| What's on the wire? | tcpdump -i any -nn host X and port Y |
Wireshark on a -w capture |
| Does HTTP work? | curl -sv --resolve host:443:IP https://host/ |
curl -w timings, openssl s_client |
| Which resource is saturated? | vmstat 1, iostat -xz 1, free -m |
mpstat, pidstat, sar, PSI in /proc/pressure |
| Where did the disk go? | df -h, df -i, du -xh --max-depth=2 / | sort -rh |
lsof +L1, ncdu -x / |
| What changed? | journalctl --since, /var/log/apt/history.log, last, etckeeper/Git log |
systemd-delta |
Configuration and certificates
| Job | Tool |
|---|---|
| service limits and sandboxing | unit files: MemoryMax=, CPUQuota=, ProtectSystem=, systemd-run -p for one-offs |
| service accounts | useradd --system, systemd-sysusers, DynamicUser=yes |
| access | sudoers.d drop-ins, AllowGroups in sshd, SSH certificates (step-ca, Vault, Teleport) |
| firewall | nftables directly, or ufw (Debian/Ubuntu), firewalld (RHEL); cloud security groups as the outer layer |
| storage | lsblk, blkid, LVM (pvs/vgs/lvs, lvextend -r), growpart, quotas (setquota, xfs_quota) |
| backups | rsync -aAXH --link-dest, restic, BorgBackup; database-native dumps and WAL/binlog archiving |
| reverse proxy | Nginx, Caddy (deeper: HAProxy, Traefik, Envoy in Web Servers in Depth) |
| certificates | certbot, acme.sh, lego, Caddy's built-in ACME, cert-manager on Kubernetes; openssl for everything by hand |
| brute-force brakes | fail2ban, CrowdSec, ufw limit, nftables limit rate |
| patching | unattended-upgrades / dnf-automatic, needrestart, Livepatch/kpatch |
Doing it at scale
Everything in this course is done on one server by hand first, so you understand it. Then it should never be done by hand again:
| Layer | Tooling | Course |
|---|---|---|
| configuration of many servers | Ansible, cloud-init for first boot | Configuration Management: Ansible |
| server images | Packer, Docker images | Docker |
| infrastructure (VMs, networks, firewalls, DNS) | Terraform / OpenTofu | Terraform & OpenTofu |
| metrics, logs, alerts | Prometheus, Grafana, Loki, the blackbox exporter | Observability |
| scripting the glue | Bash with ShellCheck, Python, Go | Automation Scripting |
Test yourself
Which command shows the effective Nginx configuration, with all included files?
- nginx -t
- nginx -T
- nginx -V
- systemctl cat nginx
ShellCheck flags for f in $(ls *.log). What is the fix?
- Use
ls -1 - Loop over the glob directly:
for f in *.log, and quote "$f" when using it - Add
set -e - Use
findwith-print
What does getent hosts name show that dig name doesn't?
- The TTL
- What applications actually resolve, including /etc/hosts and other nsswitch sources
- The authoritative server
- DNSSEC status