Linux — Level by Level›Level 2 · Cheat sheet & self-check

Level 2 — Intermediate: troubleshooting · wrap-up

Cheat sheet & self-check

Every command from this section on one page.

07 · systemd & journald in depth

Units

systemctl cat nginxShow the unit file(s) actually in use
sudo systemctl edit nginxCreate a drop-in override (survives package upgrades)
sudo systemctl daemon-reloadReload unit files after changing them
systemctl list-dependencies multi-user.targetWhat starts at boot
systemctl --failedEverything that failed

Journal

journalctl -u nginx -fFollow one service's logs
journalctl -u nginx --since '1 hour ago' -p warningWarnings and worse, last hour
journalctl -b -1 -p errErrors from the previous boot
journalctl -kKernel messages (like dmesg)
journalctl --disk-usage / sudo journalctl --vacuum-size=500MJournal size / shrink it

Boot

systemd-analyze blame | headSlowest units at boot
systemd-analyze critical-chainThe chain that delayed boot

08 · Disks & filesystems

Where did the space go?

df -hFree space per mounted filesystem
df -iFree inodes (file slots) per filesystem
sudo du -xh --max-depth=1 / | sort -rh | headBiggest top-level directories on the root filesystem
sudo lsof +L1Deleted files still held open (space not yet freed)
sudo find / -xdev -size +1G -type f 2>/dev/nullFiles over 1 GB on this filesystem

Disks & mounts

lsblk -fDisks, partitions, filesystems, mount points
findmnt /var/libWhich filesystem a path lives on
sudo mount -aMount everything in /etc/fstab (test after editing it!)

LVM grow

sudo pvs; sudo vgs; sudo lvsPhysical volumes, volume groups, logical volumes
sudo lvextend -r -L +10G /dev/vg0/dataGrow a logical volume AND its filesystem

09 · Networking from the host

Interfaces & routes

ip -br addrInterfaces and IPs, one line each
ip routeRouting table (look for 'default via')
ip route get 8.8.8.8Which interface and gateway a destination would use
ip -s link show eth0Packet and error counters

Sockets & connectivity

sudo ss -ltnpListening TCP ports and their processes
ss -tn state establishedCurrent TCP connections
nc -vz db.internal 5432Can I open a TCP connection to this port?
curl -v https://api.example.com/healthFull HTTP/TLS exchange

DNS & packets

dig +short api.example.comResolve a name
resolvectl statusWhich DNS servers this host uses (systemd-resolved)
sudo tcpdump -ni any port 5432Watch packets to/from port 5432
sudo nft list ruleset / sudo iptables -SFirewall rules

10 · Performance triage

The 60-second checklist

uptimeLoad averages: 1, 5, 15 minutes
sudo dmesg -T | tailKernel errors: OOM kills, disk or network errors
vmstat 1 5Run queue, memory, swap, I/O wait, context switches
mpstat -P ALL 1 3Per-CPU usage: one hot CPU?
pidstat 1 3Which processes use CPU
iostat -xz 1 3Per-disk utilisation and latency (await)
free -hMemory: look at 'available'
sar -n DEV 1 3Network throughput per interface
top (or htop)Everything live

Install the tools

sudo apt install -y sysstat / sudo dnf install -y sysstatProvides iostat, mpstat, pidstat, sar

11 · SSH, keys & remote work

Keys

ssh-keygen -t ed25519 -C 'asha@laptop'Create a key pair (protect it with a passphrase)
ssh-copy-id asha@web-01Install your public key on a server
ssh-add ~/.ssh/id_ed25519Load the key into the agent (type the passphrase once)
ssh -v asha@web-01Verbose: see why a login fails

Getting around

ssh -J bastion.example.com asha@10.0.5.20Jump through a bastion host
ssh -L 8080:localhost:80 asha@web-01Local port forward: laptop:8080 → web-01:80
rsync -avz --progress ./site/ asha@web-01:/srv/site/Sync a directory (only changed files)
scp backup.tar.gz asha@web-01:/tmp/Copy one file

tmux

tmux new -s workStart a named session
Ctrl+b dDetach (the session keeps running)
tmux attach -t workRe-attach later
Ctrl+b % / Ctrl+b "Split pane vertically / horizontally

12 · Checkpoint: five broken servers

Your first five commands on any sick server

uptime; free -h; df -h; df -iLoad, memory, space and inodes at a glance
systemctl --failedFailed services
journalctl -p err -b --no-pager | tail -30Recent errors this boot
sudo ss -ltnpWhat's listening
sudo dmesg -T | tail -20Kernel complaints (OOM, disk, network)