Same in the terminal
$ curl tools.otw.solutions/linux/selinuxWhole sheet in the terminal: curl tools.otw.solutions/linux | less · Debian: add ?distro=debian
Cheat sheet
The commands you need when something is broken. Written for AlmaLinux / RHEL 9, with the Debian / Ubuntu equivalents one click away.
hostnamectlHostname, OS, kernel, virtualisation
cat /etc/os-releaseDistribution and exact version
uptimeUptime and load average (1/5/15 min)
who -b; last reboot | headLast boot time and reboot history
free -hMemory and swap usage
lscpuCPU model, cores, architecture
ps aux --sort=-%cpu | headTop CPU consumers
ps aux --sort=-%mem | headTop memory consumers
topLive processes (press 1 for per-core, M sort by memory, P by CPU)
dnf install epel-release && dnf install htopInstall htop (RHEL: from EPEL)
apt install htopInstall htop
vmstat 1 5CPU, memory, swap and I/O wait, 5 samples
dnf install sysstat && iostat -xz 1Per-disk utilisation and latency
apt install sysstat && iostat -xz 1Per-disk utilisation and latency
dmesg -T --level=err,warnKernel errors and warnings with timestamps
dmesg -T | grep -i -E 'oom|killed process'Processes killed by the OOM killer
systemctl status <service>State, main PID and the last log lines
systemctl --failedAll failed units
systemctl restart <service>Restart a service
systemctl enable --now <service>Enable: start now and on every boot
systemctl disable --now <service>Disable: stop now and no longer start at boot
systemctl is-enabled <service>Starts at boot? (enabled / disabled / masked)
systemctl mask --now <service>careful Block completely: cannot be started, not even as a dependency
systemctl unmask <service>Undo mask (then enable again if needed)
systemctl list-units --type=service --state=runningRunning services
systemctl cat <service>Unit file including drop-in overrides
systemctl edit <service>Create a drop-in override (survives package updates)
systemctl daemon-reloadReload unit files after editing them
systemctl list-timersScheduled timers and their next run
systemd-analyze blame | headWhat slowed down the last boot
journalctl -u <service> -fFollow the log of one service
journalctl -u <service> --since "1 hour ago"Service log of the last hour
journalctl -p err -bAll errors since the current boot
journalctl -b -1 -p warningWarnings of the previous boot (e.g. after a crash)
journalctl -k -bKernel messages of this boot
journalctl --disk-usageSpace used by the journal
journalctl --vacuum-time=14dcareful Delete journal entries older than 14 days
tail -f /var/log/messagesGeneral system log
tail -f /var/log/syslogGeneral system log (Debian 12: install rsyslog, otherwise use journalctl)
tail -f /var/log/secureSSH logins, sudo, authentication
tail -f /var/log/auth.logSSH logins, sudo, authentication
grep 'Failed password' /var/log/secure | tailFailed SSH logins
grep 'Failed password' /var/log/auth.log | tailFailed SSH logins
tail -50 /var/log/dnf.logRecent package installs and updates
tail -50 /var/log/apt/history.logRecent package installs and updates
tail -f /var/log/audit/audit.logAudit log (SELinux denials, logins, sudo)
ip -br aInterfaces and IP addresses, one line each
ip rRouting table and default gateway
ip -s link show <interface>Packet, error and drop counters
nmcli device statusInterfaces managed by NetworkManager
cat /etc/network/interfacesInterface config (Debian server: ifupdown; Ubuntu: netplan get)
nmcli connection show <connection>Full connection settings (IP, DNS, gateway)
networkctl statusLink state if systemd-networkd is used (Ubuntu)
nmcli connection up <connection>careful Re-apply a connection after changes
systemctl restart networkingcareful Re-apply /etc/network/interfaces (Ubuntu: netplan apply)
cat /etc/resolv.confDNS servers in use
ss -tulpnListening TCP/UDP ports and their process
ss -tnp state establishedEstablished TCP connections
ping -c 4 <host>Basic reachability
tracepath <host>Path to a host (installed by default, no root needed)
dnf install mtr && mtr <host>Live traceroute with packet loss per hop
apt install mtr-tiny && mtr <host>Live traceroute with packet loss per hop
dnf install bind-utils && dig <domain>DNS lookup (add @1.1.1.1 to ask a specific server)
apt install dnsutils && dig <domain>DNS lookup (add @1.1.1.1 to ask a specific server)
curl -sv -o /dev/null https://<host>HTTP(S) request with TLS handshake and headers
dnf install nmap-ncat && nc -zv <host> <port>Is a TCP port reachable?
apt install netcat-openbsd && nc -zv <host> <port>Is a TCP port reachable?
timeout 3 bash -c "</dev/tcp/<host>/<port>" && echo openPort test without any extra tools
tcpdump -i any -nn port <port>Capture traffic on a port (install tcpdump)
ethtool <interface>Link speed, duplex, link detected
firewall-cmd --stateIs the firewall running?
ufw status verboseufw state and rules (apt install ufw, not installed by default)
systemctl enable --now firewalldEnable the firewall (now and at boot)
ufw allow OpenSSH && ufw enableEnable the firewall. Allow SSH first or you lock yourself out
systemctl disable --now firewalldcareful Disable the firewall (for testing only)
ufw disablecareful Disable the firewall (for testing only)
firewall-cmd --list-allRules of the default zone
ufw status numberedRules with numbers (for deleting)
firewall-cmd --get-active-zonesZones and their interfaces
firewall-cmd --permanent --add-service=https && firewall-cmd --reloadAllow a service permanently
ufw allow 443/tcpAllow a service permanently
firewall-cmd --permanent --remove-service=https && firewall-cmd --reloadcareful Remove an allowed service
ufw delete allow 443/tcpcareful Remove an allowed service
firewall-cmd --permanent --add-port=<port>/tcp && firewall-cmd --reloadAllow a port permanently
ufw allow <port>/tcpAllow a port permanently
firewall-cmd --permanent --remove-port=<port>/tcp && firewall-cmd --reloadcareful Remove an allowed port
ufw delete allow <port>/tcpcareful Remove an allowed port
firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=<ip> port port=22 protocol=tcp accept' && firewall-cmd --reloadAllow a port only from one source IP
ufw allow from <ip> to any port 22 proto tcpAllow a port only from one source IP
firewall-cmd --permanent --remove-rich-rule='rule family=ipv4 source address=<ip> port port=22 protocol=tcp accept' && firewall-cmd --reloadcareful Remove that source-IP rule (same text as when adding)
ufw delete allow from <ip> to any port 22 proto tcpcareful Remove that source-IP rule (same text as when adding)
ufw delete <rule-number>careful Remove a rule by its number (see ufw status numbered)
nft list rulesetThe actual kernel ruleset (nftables) behind the tools
getenforceEnforcing, Permissive or Disabled
aa-statusLoaded profiles and their mode
ausearch -m avc -ts recentRecent SELinux denials
journalctl -k | grep -i 'apparmor="DENIED"'Recent AppArmor denials
dnf install setroubleshoot-server && sealert -a /var/log/audit/audit.logDenials explained, with the suggested fix
ls -Z <path>SELinux context of files
restorecon -Rv <path>Reset file contexts, fixes most "moved files" problems
semanage fcontext -a -t httpd_sys_content_t '<path>(/.*)?' && restorecon -Rv <path>Permanently label a custom web directory
semanage fcontext -d '<path>(/.*)?' && restorecon -Rv <path>Remove that custom label again
semanage port -l | grep httpPorts a service type may bind to
semanage port -a -t http_port_t -p tcp <port>Allow a service on a non-standard port
semanage port -d -t http_port_t -p tcp <port>Remove that port permission again
getsebool -a | grep httpdSELinux booleans for a service
setsebool -P httpd_can_network_connect onEnable a boolean: let web servers/proxies make outbound connections
setsebool -P httpd_can_network_connect offDisable that boolean again
setenforce 0careful Permissive until reboot. For testing only, then fix the cause
setenforce 1Back to enforcing
aa-complain /etc/apparmor.d/<profile>careful Profile to complain mode (log only), for testing
aa-enforce /etc/apparmor.d/<profile>Profile back to enforce mode
dnf check-updateAvailable updates
apt update && apt list --upgradableAvailable updates
dnf upgradeInstall all updates
apt update && apt upgradeInstall all updates
dnf upgrade --securitySecurity updates only
unattended-upgrade --dry-run -dWhat unattended-upgrades would install
dnf install <package>Install a package
apt install <package>Install a package
dnf provides '*/bin/<command>'Which package contains a command?
apt install apt-file && apt-file update && apt-file search bin/<command>Which package contains a command?
rpm -qf <path>Which installed package owns a file?
dpkg -S <path>Which installed package owns a file?
rpm -qa | grep <name>Is a package installed, which version?
dpkg -l | grep <name>Is a package installed, which version?
rpm -V <package>Files changed since installation
dpkg --verify <package>Files changed since installation
dnf historyPackage transaction history
zgrep -h Commandline /var/log/apt/history.log*Package transaction history
dnf history undo <id>careful Roll back a transaction
dnf repolist --allRepositories and whether they are enabled
apt-cache policyEnabled repositories
dnf config-manager --set-enabled <repo>Enable a repository (e.g. crb, needed by many EPEL packages)
dnf config-manager --set-disabled <repo>Disable a repository
dnf install dnf-utils && needs-restarting -rIs a reboot required after updates?
cat /var/run/reboot-required 2>/dev/null || echo "no reboot needed"Is a reboot required after updates?
needs-restarting -sServices that need a restart after updates
apt install needrestart && needrestart -r lServices that need a restart after updates
df -hTFree space per filesystem, with type
df -iFree inodes: "disk full" with space left?
du -xh --max-depth=1 <path> 2>/dev/null | sort -hBiggest directories (stays on one filesystem)
find / -xdev -type f -size +1G -exec ls -lh {} + 2>/dev/nullFiles larger than 1 GB
lsof +L1Deleted files still held open (space not freed until restart)
lsblk -fDisks, partitions, filesystems, mount points
findmnt --verifyCheck /etc/fstab before rebooting
pvs; vgs; lvsLVM physical volumes, volume groups, logical volumes
growpart /dev/<disk> <partition-number>Grow a partition after enlarging the virtual disk (cloud-utils-growpart)
growpart /dev/<disk> <partition-number>Grow a partition after enlarging the virtual disk (cloud-guest-utils)
lvextend -r -L +<size>G /dev/<vg>/<lv>Grow a logical volume and its filesystem in one step
xfs_info /Filesystem details (RHEL default: XFS)
tune2fs -l /dev/<partition>Filesystem details (Debian default: ext4)
smartctl -a /dev/<disk>Disk health (install smartmontools)
id <user>UID, groups
sudo -l -U <user>What a user may run with sudo
usermod -aG wheel <user>Grant sudo rights (group wheel)
usermod -aG sudo <user>Grant sudo rights (group sudo)
gpasswd -d <user> wheelRevoke sudo rights (takes effect at next login)
gpasswd -d <user> sudoRevoke sudo rights (takes effect at next login)
last -n 20Recent logins
lastb -n 20Recent failed logins (root)
chage -l <user>Password age and expiry
faillock --user <user>Locked out after failed logins?
faillock --user <user> --resetUnlock the account
passwd -S <user>Password status (locked, set, expired)
sshd -tTest sshd_config before restarting sshd
ssh -vvv <user>@<host>Debug a failing SSH login from the client side
timedatectlTime, time zone, NTP sync status
chronyc trackingClock offset and sync quality (chrony)
timedatectl timesync-statusSync status (systemd-timesyncd, Debian default)
chronyc sources -vNTP servers in use
timedatectl show-timesync --allNTP servers in use
timedatectl set-timezone Europe/ViennaSet the time zone
openssl s_client -connect <host>:443 -servername <host> </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -datesCertificate of a remote server
openssl x509 -in <cert.pem> -noout -textInspect a certificate file
cp <ca.crt> /etc/pki/ca-trust/source/anchors/ && update-ca-trustTrust an internal CA system-wide
cp <ca.crt> /usr/local/share/ca-certificates/ && update-ca-certificatesTrust an internal CA system-wide
No command matches this filter.
$ curl tools.otw.solutions/linux/selinuxWhole sheet in the terminal: curl tools.otw.solutions/linux | less · Debian: add ?distro=debian