Hardening Linux: updates, permissions and Lynis
In short: Hardening means setting up a system so that it offers as little attack surface as possible. The basics are surprisingly simple: keep it current, few services, few rights, good login.
The checklist
- Automatic updates: apply security updates regularly (
unattended-upgradeson Debian/Ubuntu,dnf-automaticon Fedora/RHEL), see Package management on Linux. - Only needed services:
systemctl list-unit-files --state=enabled, switch off the superfluous (systemd). - Firewall: block everything by default, open only what is needed (Linux firewall).
- Secure SSH: keys instead of passwords, root login off, see SSH on Linux.
- Few rights: normal users,
sudoonly where needed, services with their own user (Users, groups and file permissions). - Mandatory access control: keep SELinux and AppArmor enabled.
- Encryption: disk with LUKS (partitions, LVM and encryption), traffic with HTTPS.
- Slow down brute force:
fail2banblocks addresses after many failed attempts. - Read the logs: logs and scheduling.
- Test backups (backups on Linux).
Lynis
lynis audit system checks the system and delivers a list of warnings and suggestions and a hardening index. Do not blindly apply every suggestion, but as a checklist it is very useful.
Attitude
Security is a continuous task, not a state. Every additional piece of software is more attack surface, every secret in plain text a risk.
See also: Linux in the data centre