System Hardening
Apply hardening techniques to minimize attack surface.
Hardening is the process of reducing your systemâs attack surface and making it resilient against common attacks. You donât need âperfect securityâ â you need a strong baseline thatâs repeatable across servers.
Hardening Steps
- 1.Remove unnecessary packages and services
- 2.Configure automatic security updates
- 3.Set up fail2ban for brute-force protection
- 4.Configure SELinux or AppArmor
- 5.Enable audit logging
1) Reduce running services
Every running service is a potential vulnerability. Disable anything you donât use.
$ systemctl list-unit-files --type=service --state=enabled | head
# Disable a service immediately and at boot
$ sudo systemctl disable --now cups
2) Patch management
Most real-world compromises happen through known vulnerabilities that werenât patched. Security updates matter more than âexoticâ defenses.
$ sudo apt update && sudo apt upgrade
# Enable unattended security updates (Ubuntu)
$ sudo apt install unattended-upgrades
$ sudo dpkg-reconfigure unattended-upgrades
fail2ban Configuration
fail2ban watches logs (like SSH auth logs) and bans IPs that show brute-force patterns. Itâs a strong baseline for internet-exposed SSH.
$ sudo systemctl enable fail2ban
# Check banned IPs
$ sudo fail2ban-client status sshd
3) AppArmor / SELinux
Mandatory Access Control (MAC) systems restrict what processes can do even if theyâre compromised. AppArmor is common on Ubuntu; SELinux is common on RHEL/Fedora.
$ sudo aa-status | head
# SELinux (RHEL/Fedora)
$ sestatus 2>/dev/null || echo "SELinux tools not installed"
4) Kernel & network hardening (sysctl)
sysctl tunes kernel behavior. Apply carefully and test â defaults vary by distro and environment.
# Example: basic network hardening (review before applying)
$ sudo sysctl -w net.ipv4.conf.all.rp_filter=1
$ sudo sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1
5) Auditing and visibility
If you canât see whatâs happening, you canât defend it. Logs + audit are how you detect intrusion and support incident response.
$ sudo journalctl -u ssh -n 50 --no-pager
â Practice (30 minutes)
- List enabled services and disable at least one you donât need.
- Enable unattended upgrades on a test VM and confirm itâs configured.
- Install fail2ban and check the status of the
sshdjail.