Pcornel
Linux · Security

Linux Hardening

Cheat sheet · https://pcornel.dk/topic.php?topic=2853

Back to the Topic

Answer

Linux hardening applies a baseline: minimal packages and services, automatic security updates, strong authentication, SSH hardening, firewall, MAC enforcing, secure mount options, kernel sysctl settings, auditing and logging. Benchmarks such as CIS describe it.

Remember

Automate the baseline (Ansible, OpenSCAP) rather than hand-editing. Scan with OpenSCAP (oscap) or Lynis and fix findings by priority. Test services after each hardening change.

First checks

  • sestatus / aa-status — SELinux or AppArmor state
  • ss -tulpn — listening services
  • journalctl -u sshd -g 'Failed' — failed logins
  • ausearch -m avc,user_login -ts today — audit events (auditd)

Commands

ss -ltnup
nft list ruleset
sudo
journalctl -u myapp
systemctl list-unit-files --state=enabled

Verify in this order

baseline defined → applied by automation → scanned → findings fixed → re-scanned

Where it usually breaks

First mismatch in identity/group resolution → Unix mode/ACL/capability → mount/sandbox constraint → SELinux/AppArmor policy → credential/TLS trust → protected operation; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2853

Confirmation

Confirm action

Continue?