Skip to main content

Lesson 4 of 10

System Hardening

System hardening reduces the attack surface by removing unnecessary software, disabling unneeded services, applying secure configurations, and tuning kernel parameters. A freshly installed Linux system has many insecure defaults; hardening is the process of locking it down.

60 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

Security Hardening Checklist

Security Hardening Checklist
# Linux Server Security Hardening - Step by Step

# 1. Keep system updated
apt update && apt upgrade -y           # Debian/Ubuntu
yum update -y                          # RHEL/CentOS
# Enable automatic security updates:
apt install unattended-upgrades
dpkg-reconfigure unattended-upgrades

# 2. Remove unnecessary packages
apt list --installed | less            # Review all installed software
apt remove telnet ftp rsh-client rsh-server  # Remove insecure services
apt autoremove                         # Remove orphaned dependencies

# 3. Disable unused services
systemctl list-units --type=service    # View all running services
systemctl disable bluetooth            # Disable Bluetooth (if not needed)
systemctl disable cups                 # Disable printing service (if not needed)
systemctl disable avahi-daemon         # Disable mDNS discovery

# 4. Firewall (UFW - Uncomplicated Firewall)
ufw default deny incoming              # Block all incoming by default
ufw default allow outgoing            # Allow all outgoing
ufw allow 22/tcp                      # SSH
ufw allow 443/tcp                     # HTTPS
ufw enable
ufw status verbose                     # Verify rules

Kernel Security Parameters (sysctl)

Kernel Security Parameters (sysctl)
# /etc/sysctl.conf - Kernel hardening parameters
# Apply with: sysctl -p

# Network security
net.ipv4.ip_forward = 0               # Disable IP forwarding (not a router)
net.ipv4.conf.all.send_redirects = 0  # Don't send ICMP redirects
net.ipv4.conf.all.accept_redirects = 0 # Don't accept ICMP redirects
net.ipv4.conf.all.rp_filter = 1       # Enable reverse path filtering (anti-spoofing)
net.ipv4.tcp_syncookies = 1           # Enable SYN cookies (anti SYN flood)
net.ipv4.icmp_echo_ignore_broadcasts = 1  # Ignore broadcast ICMP (smurf attacks)
net.ipv6.conf.all.disable_ipv6 = 1    # Disable IPv6 if not used

# System security
kernel.randomize_va_space = 2         # ASLR (Address Space Layout Randomization)
kernel.dmesg_restrict = 1             # Non-root cannot read kernel log
kernel.kptr_restrict = 2              # Hide kernel pointers from all users
fs.suid_dumpable = 0                  # Disable core dumps for SUID programs
kernel.yama.ptrace_scope = 1          # Restrict ptrace (anti-debugging of processes)

# Apply:
sysctl -p /etc/sysctl.conf

CIS Benchmark Hardening

  • CIS Benchmarks provide 100+ specific hardening recommendations for each OS, scored as Level 1 (essential, no impact) and Level 2 (advanced, may affect functionality)
  • Automated tools: Lynis ('lynis audit system') - scans and scores your system against security best practices, produces prioritized recommendations
  • OpenSCAP: Automated compliance scanning against CIS, DISA STIG, and other benchmarks - generates HTML reports with pass/fail for each control
  • Password policy (/etc/login.defs): Set PASS_MAX_DAYS 90, PASS_MIN_DAYS 7, PASS_WARN_AGE 14, and configure libpam-pwquality for complexity requirements
  • Account lockout (PAM): Configure pam_tally2 or pam_faillock - lock accounts after 5 failed attempts, require administrator unlock

Common Mistakes

  • Hardening production systems without testing in staging first - some kernel parameters or service disablements can break legitimate functionality
  • Only hardening servers, not workstations - workstations are the primary initial access vector and need equal hardening attention
  • One-time hardening without continuous drift monitoring - configurations change over time; use file integrity monitoring (AIDE) and compliance scanning to detect drift

Tip

Tip

Practice System Hardening in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.

Diagram
Loading diagram…

The foundational security model: Confidentiality (privacy), Integrity (trust), and Availability (uptime).

Practice Task

Note

Practice Task - (1) Write a working example of System Hardening from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.

Quick Quiz

Common Mistake

Warning

A common mistake with System Hardening is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready cybersecurity code.

Key Takeaways

  • System hardening reduces the attack surface by removing unnecessary software, disabling unneeded services, applying secure configurations, and tuning kernel parameters.
  • CIS Benchmarks provide 100+ specific hardening recommendations for each OS, scored as Level 1 (essential, no impact) and Level 2 (advanced, may affect functionality)
  • Automated tools: Lynis ('lynis audit system') - scans and scores your system against security best practices, produces prioritized recommendations
  • OpenSCAP: Automated compliance scanning against CIS, DISA STIG, and other benchmarks - generates HTML reports with pass/fail for each control

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/10 done