Security Basics — SSH, TLS and Certificates›Everyday hygiene · Cheat sheet & self-check

Everyday hygiene · wrap-up

Cheat sheet & self-check

Every command from this section on one page.

14 · Passwords, MFA and secrets

Passwords on Linux

sudo grep '^asha:' /etc/shadow | cut -d: -f2 | cut -c1-4Hash method prefix: $y$ = yescrypt, $6$ = SHA-512 crypt
sudo passwd -l olduserLock an account's password
sudo chage -l ashaPassword ageing for a user

Secrets in code

gitleaks detect --source .Scan a repository (including history) for secrets
gitleaks protect --stagedScan staged changes before committing (pre-commit hook)
git log -p -S 'AKIA'Find commits that added or removed a string
echo '.env' >> .gitignoreKeep local secret files out of Git

15 · Firewalls, open ports and patching

What is listening

sudo ss -tulpnTCP/UDP listening sockets with the owning process
sudo ss -tlpn 'sport = :5432'Who listens on one port
nmap -Pn your.server.ipWhat is reachable from outside (run from another machine you own)

ufw

sudo ufw default deny incomingBlock all incoming by default
sudo ufw default allow outgoingAllow outgoing
sudo ufw allow OpenSSHAllow SSH BEFORE enabling
sudo ufw allow 80,443/tcpAllow web traffic
sudo ufw enableTurn it on
sudo ufw status numberedList rules
sudo ufw delete 3Delete rule number 3

Patching (Ubuntu/Debian)

sudo apt update && apt list --upgradableWhat can be upgraded
sudo apt upgradeInstall upgrades
sudo apt install unattended-upgrades && sudo dpkg-reconfigure -plow unattended-upgradesAutomatic security updates
cat /var/run/reboot-requiredDoes a new kernel or library need a reboot?
sudo needrestartWhich services still run old libraries

16 · Capstone: harden a new server

Verify the result

sudo sshd -T | grep -Ei '^(permitrootlogin|passwordauthentication)'Both should be 'no'
sudo ufw status verboseDefault deny incoming; only 22 (restricted), 80, 443 allowed
sudo ss -tulpnNothing unexpected on 0.0.0.0
systemctl status unattended-upgrades fail2banBoth active
sudo certbot renew --dry-runRenewal works
curl -sI https://example.com | grep -i strict-transportHSTS present
curl -sI http://example.com | head -1301 redirect to HTTPS