Most commands here are distro-agnostic, but a few assume Debian/Ubuntu (e.g. the sudo group is named sudo, not wheel; ufw is the firewall front-end).
Networking & ports
Check which ports are open
ss -tulnp # modern, preferrednmap localhost # external viewnetstat -ntlp # legacy, deprecated on most distros
ss over netstat
netstat is part of net-tools, which is unmaintained and not installed by default on most modern distros. ss (from iproute2) is faster, ships everywhere, and uses similar flags.
ufw firewall
Use with sudo if not root. Debian/Ubuntu only — RHEL-family uses firewalld.
ufw statusufw status numbered # then ufw delete <number>ufw allow 22 # allow SSHufw delete allow 22 # remove ruleufw deny 22 # block SSHufw reset # back to defaultsufw default deny incoming # set default policiesufw default allow outgoingufw allow from 10.10.10.2 # allow specific IPufw enable
Teleport ports
If running Teleport(to write), leave ports 3022, 3023, and 3025 open.
Files & disk
Find out where all the space has gone
du -sh * | sort -h # current dir, visible files onlydu -sh .[!.]* * | sort -h # include hidden files/dirsncdu # interactive TUI alternative — recommended
ncdu is much nicer for exploration; install via apt install ncdu or equivalent.
Delete duplicate files
fdupes -rdN dir/# r - recursive# d - preserve first file, delete other dupes# N - run silently (no prompt)
Test first
-N skips confirmation. Run without -d first to list duplicates, then add -d once you’re confident.
The user must log out and back in for the group change to take effect.
See logged in users
w # users + what they're doing + load avgwho # users + login time + IPusers # just usernames, useful for scriptslast # login history since last reboot, including logged-out users
The w output columns: TTY shows the terminal (pts/N = pseudo-terminal, typically SSH); JCPU is CPU time for all processes on that TTY; PCPU is CPU time for the current foreground process.
history # find the line number, e.g. 316history -d 316 # delete that line from current sessionhistory -w # write changes to ~/.bash_history
Both steps matter
history -d only affects the current session’s in-memory history. Without history -w, the line will reappear when you start a new shell. For a clean wipe of all history: history -c && history -w.
Usually requires sudo for full access (regular users only see their own messages unless in the adm or systemd-journal group).
journalctl # all logs, paged with lessjournalctl -n 100 # last 100 entriesjournalctl -r # reverse order (newest first)journalctl -f # real-time follow (Ctrl+C to exit)journalctl -xe # last entries + extra context (great for debugging)journalctl -k # kernel messages onlyjournalctl -u ssh # specific systemd servicejournalctl -b # current bootjournalctl -b -1 # previous boot (-2 for two boots ago, etc.)journalctl --list-boots # list all available boot sessionsjournalctl --since "2020-07-10 15:10:00" --until "2020-07-12"journalctl --since yesterday # natural language works toojournalctl -p 3 -xb # errors only, this boot, with contextjournalctl --disk-usage # how much space the journal is taking
Priority levels for -p: emerg (0), alert (1), crit (2), err (3), warning (4), notice (5), info (6), debug (7). Can use a range, e.g. -p 4..6.
-xe flags broken down:
-e: jump to end of logs
-x: include extra explanatory text (subject, support URLs, job IDs)
Combining filters
Filters compose. To see only SSH errors since yesterday in UTC: