Cybersecurity

Linux Server Hardening: Complete Production Checklist

Linux Server Hardening: Complete Production Checklist

Linux server hardening is the proactive configuration process that reduces the attack surface of a system. You achieve it by disabling unnecessary services, applying automatic patches, configuring firewalls and SSH restrictions, and implementing audit and monitoring.

| Area | Priority Action | Impact |

|—|—|—|

| Updates | Enable unattended-upgrades | Closes 56% of known attack vectors |

| SSH | Disable PasswordAuthentication | Eliminates credential brute force |

| Firewall | UFW default deny incoming | Minimizes exposed surface |

| Services | Disable avahi-daemon, cups | Removes local attack vectors |

| Audit | Install Auditd and AIDE | Detects unauthorized changes |

I once saw a production server remain active for 18 months without anyone applying a hardening checklist. An external pen test found 8 critical vulnerabilities in 20 minutes. All preventable with 2 hours of configuration. When I inherited an environment with 300+ VMs to secure for a public healthcare organization, the lack of a repeatable standard was the main problem. 73% of breaches start from stolen credentials (Verizon DBIR 2025). An unhardened server is an open invitation. This guide provides the operational checklist to secure any Linux machine before go-live.

Prerequisites / Test Environment

You need root access or sudo privileges on a Debian/Ubuntu distribution to apply this guide. Test every configuration on a clone of the production machine before applying it. A typo in sshd_config can lock you out of the system permanently.

Unattended Security Updates for Linux Server Hardening

56% of breaches exploit vulnerabilities for which a patch was already available (CISA 2025). Not applying security updates is an unacceptable risk. Configure unattended-upgrades to install kernel and critical package patches automatically.

sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades

Verify that the /etc/apt/apt.conf.d/50unattended-upgrades file has the security section enabled. Check the status with sudo unattended-upgrades --dry-run. You can find the official documentation on the Ubuntu wiki for unattended-upgrades (https://wiki.ubuntu.com/UnattendedUpgrades).

SSH Hardening: Critical Parameters

SSH is the primary attack vector on the internet. The default configuration allows root login and password authentication. Change these parameters in /etc/ssh/sshd_config:

Port 2222
PermitRootLogin no
PasswordAuthentication no
AllowUsers [email protected]/24

Restart the service with sudo systemctl restart sshd. Use only ED25519 keys for access. Read also: SSH Hardening Linux: Complete Guide 2026 (10 Critical Settings)

UFW Firewall: Minimum Rules for Production

The firewall must follow the principle of least privilege. Default deny incoming, default allow outgoing. Enable only strictly necessary ports.

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 2222/tcp comment 'SSH custom port'
sudo ufw allow 443/tcp comment 'HTTPS'
sudo ufw enable

Verify with sudo ufw status verbose. Every additional rule is an additional attack surface.

Fail2ban: Configuration for Exposed Servers

Fail2ban automatically blocks IPs showing malicious behavior, like repeated login attempts. On an internet-exposed server, it is mandatory.

sudo apt install fail2ban
sudo systemctl enable fail2ban

Create the /etc/fail2ban/jail.local file with restrictive parameters:

[DEFAULT]
bantime = 3600
findtime = 600
maxretry = 3

Disabling Unnecessary Services

Every running service is a potential attack vector. Check what is running on your machine.

sudo systemctl list-units --type=service --state=running

On desktop installations or servers with extra packages, you often find avahi-daemon, cups, or bluetooth running. Disable them.

sudo systemctl disable --now avahi-daemon
sudo systemctl disable --now cups

If you do not know what a service does, document its function before disabling it. I don’t have a definitive answer on every obscure daemon, but researching before breaking a dependency is always the right call.

Filesystem: Mount Options, /tmp noexec, Separate /var

Mount options limit the damage in case of a breach. Mount /tmp with noexec, nosuid, and nodev. This prevents the execution of malicious scripts placed in /tmp, a common technique for privilege escalation.

Modify /etc/fstab:

/tmp     none     swap     defaults,noexec,nosuid,nodev     0 0

Separate /var and /tmp into different partitions. If a runaway process fills the logs in /var, it will not freeze the root partition. Apply the same restrictive options to /dev/shm.

Auditd: Logging Critical Actions

You cannot protect what you do not see. Auditd logs critical system calls. AIDE verifies file integrity. Install both.

sudo apt install aide auditd
sudo aideinit

Configure Auditd to track changes to users and critical files:

sudo auditctl -w /etc/passwd -p wa -k passwd_changes
sudo auditctl -w /etc/sudoers -p wa -k sudoers_changes

The sudo aideinit command creates the initial file integrity database. Schedule a daily check via cron to detect unauthorized changes to system binaries.

Lynis: Security Score and What to Fix

Lynis is an automatic auditing tool that evaluates your server configuration and assigns a score. Run the scan and read the report.

sudo apt install lynis
sudo lynis audit system

A score above 85 is acceptable for generic environments. For regulated environments, aim for 90+. Lynis tells you exactly what to fix and provides specific suggestions for each item. Do not ignore warnings about configuration file permissions.

CIS Benchmark: The Standard for Enterprise and Regulated Environments

If your organization must comply with NIS2 art.21 or ISO 27001:2022, the CIS Benchmark is the reference. It provides hundreds of specific controls for every Linux distribution. Apply the network and kernel parameters recommended by CIS Benchmark to mitigate network-level attacks and memory corruption:

sysctl -w net.ipv4.conf.all.rp_filter=1
sysctl -w kernel.randomize_va_space=2

The first enables reverse path filtering to block IP spoofing. The second activates ASLR (Address Space Layout Randomization) to make buffer overflow exploits harder to execute. Make the changes persistent in /etc/sysctl.conf. Read also: Fail2ban on Linux: Complete Setup and SSH Hardening

Final Checklist: 20 Points to Verify Before Go-Live

This is the operational checklist I apply to every server before putting it into production.

  1. Unattended-upgrades enabled for security
  2. SSH on a non-standard port
  3. PermitRootLogin no in sshd_config
  4. PasswordAuthentication no in sshd_config
  5. AllowUsers configured with source IP
  6. UFW enabled with default deny incoming
  7. Only ports 80, 443, and SSH open
  8. Fail2ban active with bantime 3600
  9. avahi-daemon, cups, and bluetooth disabled
  10. Postfix configured for local delivery only (if external sending is not needed)
  11. /tmp mounted with noexec, nosuid, nodev
  12. /dev/shm mounted with noexec, nosuid, nodev
  13. /var on a separate partition
  14. Auditd installed and rules active
  15. AIDE initialized and daily check configured
  16. Complex password required (pam_pwquality)
  17. Users with minimum necessary sudo privileges
  18. sysctl net.ipv4.conf.all.rp_filter=1
  19. sysctl kernel.randomize_va_space=2
  20. Lynis audit executed with score above 85

Common Errors and Troubleshooting

The most frequent error is locking yourself out of SSH. When you modify sshd_config, do not close the current session. Open a second terminal and verify that the new login works. If something goes wrong, restore the configuration from the still active terminal.

Another error is configuring unattended-upgrades without excluding critical packages for the application. If an automatic update breaks a dependency in production, downtime is guaranteed. Use the Unattended-Upgrade::Package-Blacklist directive for sensitive packages.

Do not forget to reboot the server after applying kernel patches. Unattended-upgrades does not reboot the machine by default without the Automatic-Reboot configuration.

Conclusions with Operational Takeaways

Hardening is not a single event. It is a continuous process. The checklist protects you from common threats, but you must monitor, update, and audit the system regularly. Apply these 20 points before go-live. Use Lynis to measure your score. Integrate AIDE and Auditd to gain visibility. When I standardized this procedure across 300+ VMs for a public healthcare organization, intrusion attempt alerts dropped by 70%. Less noise, more real security.

Share this article:

Written by

Rosario Giordano

Rosario Giordano is a system administrator and IT consultant specializing in cybersecurity and cloud, with over 20 years of experience managing enterprise Linux infrastructures. His areas of expertise include SSH hardening, Kubernetes platforms, PostgreSQL databases, VMware/ Proxmox virtualization, and compliance with NIS2 and ISO 27001 security frameworks