Cheat SheetsLinux Administration Pro Reference

Linux Administration — Pro Reference

System Service & Daemon Management

Actionsystemctl Commandjournalctl Command
Status / PIDsystemctl status <svc>journalctl -u <svc> -n 50
Start / Stopsystemctl start|stop <svc>journalctl -u <svc> -S "1 hour ago"
Graceful Reloadsystemctl reload <svc>journalctl -u <svc> -f (Live tail)
Boot Startupsystemctl enable|disable <svc>journalctl -b (Current boot logs)
Config Updatesystemctl daemon-reload(Run after modifying .service files)

Process Control & Signals

TaskCommandDescription
Static Snapshotps aux | grep -v grep | grep <name>Find PID across all users.
Find PID Fastpgrep <name>Returns only the PID number.
Live Monitortop / htopInteractive resource consumption.
Polite Termkill <PID> / pkill <name>Sends SIGTERM (15). Graceful exit.

[!CAUTION] SIGKILL (kill -9) Execution: kill -9 <PID> completely bypasses the application and drops a kernel-level termination. It causes database corruption if active transactions exist. Only use if SIGTERM fails after 30 seconds.

Permission Hardening & Octals

TargetOctalSymbolicDescription
Scripts / Dirs755u=rwx,go=rxOwner can read/write/exec. Everyone can read/exec.
Config / Text644u=rw,go=rOwner can read/write. Everyone can read.
SSH / Secrets600u=rw,go=Owner read/write only. Fails SSH checks if open.
Recursion-Rchmod -R 755 dir/Applies to all files and subdirectories.

Ownership Updates: sudo chown user:group file sudo chown -R user:group directory/

[!CAUTION] Avoid chmod -R when possible. Use find to surgically target files vs directories. Files: find /path -type f -exec chmod 644 {} \+ Dirs: find /path -type d -exec chmod 755 {} \+

Network Diagnostics

ScopeCommandPurpose
Interfaces/IPsip addr showIdentify local network interfaces and assigned IPs.
Routesip route showIdentify default gateway and static routes.
Listening Socketssudo ss -tulpnCrucial: Requires sudo to display owning Process IDs.
Specific Portsudo ss -tulpn | grep :<port>Isolates active socket binding (e.g., grep :80).
HTTP Headerscurl -I <url>Fetch response headers only (HTTP 200, 500).
Health Checkcurl -f <url>Fails silently with exit code > 0 on HTTP errors.

Package Automation

ActionDebian/Ubuntu (apt)RHEL/Fedora (dnf)
Update Cachesudo apt updatesudo dnf check-update
Installsudo apt install -y <pkg>sudo dnf install -y <pkg>
Removesudo apt remove -y <pkg>sudo dnf remove -y <pkg>
Clean Orphanssudo apt autoremove -ysudo dnf autoremove -y

[!TIP] Container Optimization: Always clean the package cache in the same RUN layer: RUN apt update && apt install -y curl && rm -rf /var/lib/apt/lists/*

Production Bash Snippets

Strict Mode Header:

#!/bin/bash
set -euo pipefail
# -e: Abort on non-zero exit code
# -u: Abort on unbound (undefined) variable
# -o pipefail: Abort if any command in a pipeline fails

Systemd Unit Template (/etc/systemd/system/myapp.service):

[Unit]
Description=My Custom Microservice
After=network.target
 
[Service]
ExecStart=/usr/bin/python3 /opt/myapp/app.py
Restart=on-failure
RestartSec=5s
User=appuser
 
[Install]
WantedBy=multi-user.target