Linux Hardening Best Practices for Enterprise Infrastructure
A field-tested framework for locking down Linux servers in regulated Canadian environments — from CIS benchmarks to kernel-level controls.
Why hardening is non-negotiable in 2026
Default Linux installations are built for compatibility, not security. In enterprise and government environments — where a single misconfigured server can expose sensitive data or trigger a compliance breach — relying on defaults is a liability. The 2025 Canadian Centre for Cyber Security (CCCS) threat report identified misconfigured Linux systems as the second most common initial access vector in incidents affecting federal agencies and Crown corporations.
Hardening is the process of systematically reducing that attack surface. Done correctly, it does not impair performance or operability — it creates a documented, auditable baseline that satisfies frameworks including CIS Level 2, NIST SP 800-123, ISO 27001 Annex A, and PIPEDA technical safeguard requirements.
1. Start with CIS Benchmarks
The Centre for Internet Security (CIS) publishes hardening benchmarks for every major Linux distribution — RHEL, Ubuntu, Debian, Rocky Linux, and Amazon Linux. Each benchmark contains hundreds of controls grouped into two profiles: Level 1 (minimal operational impact) and Level 2 (defence-in-depth for high-security environments). For most Canadian enterprises, Level 1 is the baseline; regulated sectors (financial services, defence, healthcare) should target Level 2.
- Run the CIS-CAT Pro scanner or open-source equivalent (OpenSCAP) against every new server before it enters production
- Remediate all Level 1 failures before go-live; document accepted exceptions for Level 2 controls with a risk owner sign-off
- Re-scan quarterly and after every major OS update — benchmarks evolve and so does your configuration drift
- Automate remediation with Ansible roles (e.g. ansible-lockdown/RHEL9-CIS) to enforce consistency across fleets
2. Enforce Mandatory Access Control
Discretionary access control (file permissions, ACLs) is necessary but insufficient. Mandatory Access Control (MAC) enforces policy at the kernel level, confining processes to only the resources they legitimately need — even if an attacker achieves code execution. On RHEL/Rocky/CentOS, SELinux is the standard; on Ubuntu/Debian, AppArmor fills the same role.
- Never set SELinux to Permissive in production — Enforcing mode is the only configuration that provides protection
- Use targeted policy (the default) rather than MLS unless you have a specific multi-level security requirement
- Audit AVC denials with ausearch -m avc -ts recent and generate custom policy modules with audit2allow only after reviewing each denial
- For AppArmor: enforce profiles for all internet-facing services (nginx, Apache, sshd, PostgreSQL) and use aa-genprof to build profiles for custom applications
3. Kernel-Level Hardening Parameters
The Linux kernel exposes hundreds of tunable parameters via /proc/sys and sysctl. A targeted subset of these parameters significantly reduces the exploitability of common vulnerability classes — stack overflows, ASLR bypasses, IP spoofing, and SYN flood attacks.
- kernel.randomize_va_space = 2 — full ASLR for stack, heap, and shared libraries
- kernel.dmesg_restrict = 1 — prevents unprivileged users from reading kernel ring buffer (leaks memory addresses)
- net.ipv4.conf.all.rp_filter = 1 — strict reverse path filtering to block spoofed packets
- net.ipv4.tcp_syncookies = 1 — SYN flood mitigation without dropping legitimate connections
- fs.protected_hardlinks = 1 and fs.protected_symlinks = 1 — prevent privilege escalation via symlink/hardlink attacks
- kernel.yama.ptrace_scope = 1 — restrict ptrace to parent processes only, blocking many local privilege escalation techniques
4. Comprehensive Audit Logging
You cannot investigate what you did not log. The Linux Audit Framework (auditd) provides kernel-level event capture that is significantly harder to tamper with than application-level logging. Combined with a centralised SIEM, it creates the forensic trail required by SOC 2, ISO 27001, and PIPEDA breach notification obligations.
- Log all privileged command executions: -a always,exit -F arch=b64 -S execve -F euid=0 -k privileged-exec
- Capture all authentication events, sudo usage, and changes to /etc/passwd, /etc/shadow, and /etc/sudoers
- Monitor writes to /boot, /etc/cron*, and /var/spool/cron — common persistence locations
- Ship logs to an immutable, off-host destination (Splunk, Elastic, or a managed SIEM) within 60 seconds — local-only logs can be wiped by an attacker with root access
- Set auditd to halt the system on log failure (action_mail_acct and space_left_action = SYSLOG; admin_space_left_action = HALT) in high-assurance environments
5. A Repeatable Patch Cadence
Hardening is a point-in-time activity; patch management is the ongoing discipline that keeps it effective. The majority of successful Linux compromises exploit known vulnerabilities for which patches have been available for weeks or months. A structured cadence eliminates that window.
- Critical CVEs (CVSS ≥ 9.0): patch within 72 hours in non-production, 7 days in production with change-board approval
- High CVEs (CVSS 7.0–8.9): patch within 30 days; include in the next scheduled maintenance window
- Medium and below: patch monthly during the standard maintenance cycle
- Use dnf-automatic or unattended-upgrades for security-only patches in non-production; require human approval for production
- Maintain a tested rollback procedure — snapshot before patching, validate with a smoke-test suite, keep the snapshot for 72 hours post-patch
Building a hardening programme, not a one-time project
The organisations that maintain the strongest Linux security posture treat hardening as a continuous programme — not a pre-launch checklist. That means automated scanning, policy-as-code, centralised logging, and a patch cadence that is enforced rather than aspirational. It also means regular red-team exercises to validate that controls are working as intended, not just configured.
Alhassan Consultancy's Linux Resilience practice helps Canadian enterprises build and operate hardened Linux environments that satisfy regulatory requirements and withstand real-world threat actors. Book a confidential assessment to benchmark your current posture.