This is the capstone lesson of our course, where we bring together everything you have learned — filesystem navigation, user management, permissions, process monitoring, firewall configuration, SSH hardening, logging, and SELinux — into two critical professional skills: system hardening and incident response. By the end of this lesson, you will be able to harden a Linux system against attacks and respond effectively when a breach occurs.
Hardening is the process of reducing a system's attack surface by removing unnecessary components, configuring security controls, and applying patches. It follows a systematic methodology: assess, configure, verify, and maintain. We will walk through each phase with practical commands.
Before hardening, you need to understand the current state. This assessment reveals what needs to be fixed.
💡 The password policy above (PASS_MAX_DAYS=99999, PASS_MIN_DAYS=0) is a finding. Passwords should expire every 90 days maximum, and users should not be able to change passwords immediately (minimum 1 day). These are common compliance violations.
The kernel is the foundation of the OS. Securing kernel parameters (sysctl) provides protection against many network-level attacks.
# /etc/sysctl.d/99-security.conf — Kernel Hardening
# Disable IP forwarding (unless this is a router)
net.ipv4.ip_forward = 0
net.ipv6.conf.all.forwarding = 0
# Enable SYN flood protection
net.ipv4.tcp_syncookies = 1
# Disable source routing
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
# Disable ICMP redirects
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
# Enable reverse path filtering (anti-spoofing)
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
# Log martian packets (suspicious source addresses)
net.ipv4.conf.all.log_martians = 1
# Ignore ICMP broadcast requests (Smurf attack prevention)
net.ipv4.icmp_echo_ignore_broadcasts = 1
# Ignore bogus ICMP errors
net.ipv4.icmp_ignore_bogus_error_responses = 1
# Disable IPv6 if not needed
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
# Increase ephemeral port range
net.ipv4.ip_local_port_range = 1024 65535
# Apply settings
# sudo sysctl -p /etc/sysctl.d/99-security.confWith the kernel secured, we harden services and user accounts. This is where most of the practical security work happens.
After hardening, you need to detect unauthorized changes. File integrity monitoring (FIM) tools create cryptographic hashes of critical files and alert when they change.
⚠️ AIDE detected changes in /etc/passwd and /etc/shadow. This could be legitimate (a new user was added) or malicious (an attacker created a backdoor account). Always investigate FIM alerts before dismissing them. Compare the changes against your change management records.
Despite all hardening, breaches can still happen. When they do, you need a systematic incident response process. The SANS PICERL framework (Preparation, Identification, Containment, Eradication, Recovery, Lessons Learned) applies directly to Linux incident response.
The first step is confirming that an incident has actually occurred. Here are the key Linux commands for identification:
The output above shows multiple critical indicators of compromise: (1) a deleted executable running as python3 with a reverse shell connection, (2) a hidden cron job in /tmp, (3) an unauthorized SSH key, and (4) a library injection via ld.so.preload. This system is actively compromised and needs immediate containment.
Once you identify a breach, contain it without destroying evidence. The priority order is: preserve volatile evidence, isolate the system, then begin eradication.
# === CONTAINMENT CHECKLIST ===
# 1. DO NOT power off the system (loses RAM evidence)
# 2. Capture volatile evidence FIRST:
# Memory capture (if LiME is available)
sudo insmod lime.ko "path=/tmp/memdump.lime format=lime"
# Running process list
ps auxww > /tmp/evidence_processes.txt
# Network connections
ss -tnp > /tmp/evidence_connections.txt
ss -ulnp > /tmp/evidence_listeners.txt
# ARP cache
ip neigh show > /tmp/evidence_arp.txt
# Loaded kernel modules
lsmod > /tmp/evidence_modules.txt
# Open files
lsof > /tmp/evidence_openfiles.txt 2>/dev/null
# 3. Isolate the system (but keep it running)
sudo ip link set eth0 down
# OR use firewall to block all traffic:
sudo iptables -P INPUT DROP
sudo iptables -P OUTPUT DROP
sudo iptables -P FORWARD DROP
# Keep one management interface up for forensics
# 4. Capture disk evidence (after isolation)
sudo dd if=/dev/sda of=/tmp/disk_image.dd bs=4M status=progress
# OR use dcfldd for hashing:
sudo dcfldd if=/dev/sda of=/tmp/disk_image.dd hash=sha256 hashlog=/tmp/disk_hash.txt
# 5. Secure the evidence
sha256sum /tmp/evidence_*.txt > /tmp/evidence_checksums.txt
sha256sum /tmp/disk_image.dd >> /tmp/evidence_checksums.txt
# 6. Document everything
echo "Incident response started: $(date -u)" >> /tmp/ir_timeline.txt
echo "System: $(hostname) - $(uname -a)" >> /tmp/ir_timeline.txt
echo "Analyst: $(whoami)" >> /tmp/ir_timeline.txtAfter containment and evidence preservation, you eradicate the threat and restore the system. In many cases, the safest approach is a full rebuild from known-good media.
Here is a consolidated hardening checklist that combines everything from this course into a single reference:
| Category | Action | Priority |
|---|---|---|
| Updates | Apply all security patches; enable automatic updates | Critical |
| Services | Disable all unnecessary services | Critical |
| Firewall | Default deny incoming; allow only required ports | Critical |
| SSH | Key-only auth, no root login, fail2ban, rate limiting | Critical |
| Users | Strong password policy, remove unused accounts, sudo restrictions | High |
| Permissions | Audit SUID files, set secure umask, fix world-writable files | High |
| Kernel | SYN cookies, disable forwarding, enable ASLR, rp_filter | High |
| Logging | Centralized logging, auditd rules, append-only logs | High |
| MAC | Enable SELinux/AppArmor in enforcing mode | Medium |
| FIM | Deploy AIDE or OSSEC for file integrity monitoring | Medium |
| Network | Disable IPv6 if unused, secure DNS, use TLS | Medium |
| Monitoring | Deploy IDS (Snort/Suricata), log analysis, alerting | Medium |
Congratulations! You have completed Linux for Security Professionals. You now have the skills to navigate the Linux filesystem, manage users and permissions, configure firewalls, harden SSH, implement logging and auditing, enforce mandatory access control with SELinux, and respond to security incidents. These are the foundational skills for every Linux security role — from SOC analyst to penetration tester to incident responder. Continue practicing in your lab, pursue certifications (CompTIA Linux+, RHCSA, LPIC-1), and build on this foundation with advanced topics like container security, cloud hardening, and threat hunting.
Verify exercises to earn ★ 200 XP and unlock next lab level.