Everyday hygiene · wrap-up
Cheat sheet & self-check
Every command from this section on one page.
Passwords on Linux
sudo grep '^asha:' /etc/shadow | cut -d: -f2 | cut -c1-4 | Hash method prefix: $y$ = yescrypt, $6$ = SHA-512 crypt |
sudo passwd -l olduser | Lock an account's password |
sudo chage -l asha | Password ageing for a user |
Secrets in code
gitleaks detect --source . | Scan a repository (including history) for secrets |
gitleaks protect --staged | Scan staged changes before committing (pre-commit hook) |
git log -p -S 'AKIA' | Find commits that added or removed a string |
echo '.env' >> .gitignore | Keep local secret files out of Git |
What is listening
sudo ss -tulpn | TCP/UDP listening sockets with the owning process |
sudo ss -tlpn 'sport = :5432' | Who listens on one port |
nmap -Pn your.server.ip | What is reachable from outside (run from another machine you own) |
ufw
sudo ufw default deny incoming | Block all incoming by default |
sudo ufw default allow outgoing | Allow outgoing |
sudo ufw allow OpenSSH | Allow SSH BEFORE enabling |
sudo ufw allow 80,443/tcp | Allow web traffic |
sudo ufw enable | Turn it on |
sudo ufw status numbered | List rules |
sudo ufw delete 3 | Delete rule number 3 |
Patching (Ubuntu/Debian)
sudo apt update && apt list --upgradable | What can be upgraded |
sudo apt upgrade | Install upgrades |
sudo apt install unattended-upgrades && sudo dpkg-reconfigure -plow unattended-upgrades | Automatic security updates |
cat /var/run/reboot-required | Does a new kernel or library need a reboot? |
sudo needrestart | Which services still run old libraries |
Verify the result
sudo sshd -T | grep -Ei '^(permitrootlogin|passwordauthentication)' | Both should be 'no' |
sudo ufw status verbose | Default deny incoming; only 22 (restricted), 80, 443 allowed |
sudo ss -tulpn | Nothing unexpected on 0.0.0.0 |
systemctl status unattended-upgrades fail2ban | Both active |
sudo certbot renew --dry-run | Renewal works |
curl -sI https://example.com | grep -i strict-transport | HSTS present |
curl -sI http://example.com | head -1 | 301 redirect to HTTPS |