Skip to content

Linux Server Hardening Checklist: 15 Essential Steps to Secure a Fresh VPS in Production

Deploying a brand-new virtual private server takes less than sixty seconds, yet automated botnets begin scanning that fresh IP address for open ports and weak credentials almost immediately. Without a structured Linux server hardening checklist, default operating system configurations leave critical attack surfaces wide open—prioritizing initial setup convenience over production-grade defense-in-depth.

Whether you are provisioning a cloud instance for a high-traffic web application, a database cluster, or internal microservices, security cannot be an afterthought. A single unpatched service, an exposed password-authenticated SSH daemon, or an overly permissive firewall rule can compromise your entire infrastructure within hours of launch.

This comprehensive Linux server hardening checklist walks you through 15 battle-tested steps to lock down a fresh VPS before routing production traffic to it. The commands and configuration files below apply cleanly across modern Debian-based distributions (Ubuntu 22.04/24.04 LTS, Debian 12) and Enterprise Linux derivatives (AlmaLinux 9, Rocky Linux 9, RHEL).

Linux server hardening checklist defense-in-depth architecture diagram showing SSH, firewall, kernel, and monitoring layers
A layered Linux server hardening checklist secures access control, network perimeters, kernel parameters, and audit logging.

Why Every Production Deployment Needs a Linux Server Hardening Checklist

Default cloud images from hosting providers ship with broad compatibility in mind. Root login may be enabled out of the box, network services frequently bind to all interfaces, and kernel networking parameters rarely account for modern volumetric or protocol-level abuse.

Following a repeatable Linux server hardening checklist eliminates human error during server provisioning. Instead of relying on memory when spinning up new nodes, your engineering team gains a deterministic security baseline aligned with industry standards such as the CIS Distribution Independent Linux Benchmark.

If you are still evaluating infrastructure tiers before locking down your environment, review our comparison of VPS vs. dedicated server architectures to ensure your underlying isolation model matches your compliance requirements.

Summary Matrix: The Complete 15-Step Linux Server Hardening Checklist

Before diving into terminal commands and configuration files, use the reference matrix below from this Linux server hardening checklist to map out each security control, its target layer, and the primary threat it neutralizes.

Step Security Control Primary Tool / Config Threat Mitigated
01 Automated Security Patching unattended-upgrades / dnf-automatic Known CVEs and unpatched zero-days
02 Least-Privilege Admin Account adduser + sudo / wheel Accidental root damage and anonymous actions
03 Cryptographic Key Authentication ssh-ed25519 key pairs Credential stuffing and password guessing
04 OpenSSH Daemon Lockdown /etc/ssh/sshd_config.d/99-hardening.conf Root brute-force and protocol downgrade attacks
05 Multi-Factor SSH Authentication PAM TOTP / FIDO2 hardware keys Stolen private keys or compromised workstations
06 Default-Deny Host Firewall ufw / nftables / firewalld Unauthorized port probing and service exposure
07 Automated Intrusion Prevention fail2ban or CrowdSec Distributed brute-force and scanner floods
08 Socket & Interface Auditing ss -tulpn + interface binding Accidental public exposure of internal databases
09 Kernel Parameter Hardening /etc/sysctl.d/99-security.conf SYN floods, IP spoofing, and memory exploits
10 Mandatory Access Control (MAC) AppArmor or SELinux Lateral movement after application compromise
11 Filesystem & Shared Memory Locks /etc/fstab (noexec,nosuid,nodev) In-memory payload execution via /tmp or /dev/shm
12 SUID/SGID & Cron Restrictions find + permission hardening Local privilege escalation vectors
13 Kernel-Level System Auditing auditd rulesets Undetected tampering with system binaries/configs
14 File Integrity & Rootkit Checks AIDE and rkhunter Persistent backdoors and modified system files
15 Encrypted Off-Site Backups & Logs restic / borg + remote syslog Ransomware encryption and log deletion

Phase 1: Identity, Access, and SSH Lockdown

Your first priority in any Linux server hardening checklist is securing the administrative control plane. Because SSH is the primary entry point for server management, hardening authentication and privilege boundaries prevents the vast majority of automated intrusions.

Step 1: Update System Packages and Enable Unattended Security Patches

Cloud OS images are often built weeks or months before you spin up an instance. Consequently, your very first action in this Linux server hardening checklist must be updating the local package index and applying all pending security patches.

On Ubuntu or Debian systems, run the following commands as root:

apt update && apt upgrade -y
apt install -y unattended-upgrades apt-listchanges needrestart

Next, enable automatic daily installation of security updates so critical vulnerabilities do not sit unpatched between manual maintenance windows:

dpkg-reconfigure --priority=low unattended-upgrades

On AlmaLinux, Rocky Linux, or RHEL systems, update all packages and enable dnf-automatic for security-only updates:

dnf upgrade --refresh -y
dnf install -y dnf-automatic
sed -i 's/^upgrade_type = default/upgrade_type = security/' /etc/dnf/automatic.conf
sed -i 's/^apply_updates = no/apply_updates = yes/' /etc/dnf/automatic.conf
systemctl enable --now dnf-automatic.timer

Additionally, inspect whether a kernel update was installed during this initial upgrade. If needrestart (Debian/Ubuntu) or needs-restarting -r (RHEL-based) indicates a pending kernel reboot, reboot the VPS immediately before proceeding.

Step 2: Create a Dedicated Non-Root Sudo User

The second control in our Linux server hardening checklist addresses privilege separation, because operating routinely as the root user violates the principle of least privilege. A single mistyped command or a compromised script running under root privileges has unrestricted access to every file, kernel module, and network socket on the machine.

Create a named administrative user so every privileged action is explicitly invoked with sudo and logged to /var/log/auth.log or /var/log/secure:

# On Ubuntu / Debian:
adduser deployadmin
usermod -aG sudo deployadmin

# On AlmaLinux / Rocky Linux / RHEL:
useradd -m -s /bin/bash deployadmin
passwd deployadmin
usermod -aG wheel deployadmin

Before moving forward, open a second terminal window, log in as deployadmin, and verify that sudo whoami returns root. Keep your initial root session open until SSH key authentication is fully tested.

Step 3: Enforce Ed25519 SSH Key Authentication

Enforcing cryptographic key pairs is a non-negotiable milestone in any modern Linux server hardening checklist, as passwords are fundamentally weak against modern GPU-accelerated cracking rigs and distributed botnets. SSH key pairs replace guessable strings with asymmetric cryptography, making brute-force login attempts mathematically infeasible.

On your local workstation (not the server), generate a modern Ed25519 key pair protected by a strong passphrase. Ed25519 offers superior security and faster verification compared to legacy 2048-bit RSA keys:

ssh-keygen -t ed25519 -a 100 -C "deployadmin@prod-vps-01"

Copy your public key to the new user account on the server using ssh-copy-id:

ssh-copy-id -i ~/.ssh/id_ed25519.pub deployadmin@YOUR_SERVER_IP

If you copy the public key manually, verify strict filesystem permissions on the server. OpenSSH will silently reject keys if directory or file permissions are too loose:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R deployadmin:deployadmin ~/.ssh

Test logging in from a new terminal session using your SSH key. Confirm that you authenticate smoothly using your key passphrase without being prompted for the server account password.

Step 4: Harden the OpenSSH Daemon Configuration (sshd_config)

Once key-based authentication is confirmed working, the next step in this Linux server hardening checklist is locking down the OpenSSH server daemon. Rather than editing /etc/ssh/sshd_config directly—which can trigger package merge conflicts during OS upgrades—place your overrides inside a modular drop-in file under /etc/ssh/sshd_config.d/.

For a deeper breakdown of cryptographic ciphers and bastion architectures, explore our guide on SSH security best practices. Create /etc/ssh/sshd_config.d/99-hardening.conf with the following directives:

# Disable direct root login and password authentication
PermitRootLogin no
PasswordAuthentication no
PermitEmptyPasswords no
KbdInteractiveAuthentication no
PubkeyAuthentication yes

# Restrict access strictly to named administrative users
AllowUsers deployadmin

# Limit authentication attempts and grace period
MaxAuthTries 3
MaxSessions 4
LoginGraceTime 30

# Disable unnecessary forwarding features
X11Forwarding no
AllowAgentForwarding no
AllowTcpForwarding no
PermitTunnel no

# Disconnect idle sessions after 10 minutes (300s x 2)
ClientAliveInterval 300
ClientAliveCountMax 2

# Enforce modern key exchange, cipher, and MAC algorithms
KexAlgorithms [email protected],curve25519-sha256,[email protected]
Ciphers [email protected],[email protected],[email protected]
MACs [email protected],[email protected]

Always validate your syntax against the OpenSSH daemon configuration specification before reloading the service. A syntax error could lock you out of a remote VPS:

sudo sshd -t
sudo systemctl reload sshd
Linux server hardening checklist SSH configuration and key authentication verification flow
Validating sshd_config syntax with sshd -t before reloading prevents accidental remote lockouts during your Linux server hardening checklist rollout.

Step 5: Add Multi-Factor Authentication (2FA) or Hardware Security Keys

Adding multi-factor authentication elevates a standard Linux server hardening checklist to enterprise compliance standards, ensuring that even a compromised developer laptop exposing an unencrypted private SSH key is insufficient to gain shell access.

You have two clean options depending on your team workflow:

  • FIDO2 Hardware Keys (Recommended): If your team uses YubiKeys or Titan Security Keys, generate a resident hardware-backed SSH key directly via ssh-keygen -t ed25519-sk. OpenSSH 8.2+ supports FIDO2 natively without installing extra PAM modules.
  • Time-Based One-Time Passwords (TOTP): Install libpam-google-authenticator (Debian/Ubuntu) or google-authenticator (RHEL/EPEL), run google-authenticator as your admin user, and require both publickey and keyboard-interactive via AuthenticationMethods publickey,keyboard-interactive in your SSH drop-in file.

Phase 2: Network Perimeter & Automated Intrusion Prevention

With authentication locked down, the second phase of our Linux server hardening checklist shrinks the server’s external network footprint. Every open port represents a software daemon parsing untrusted packets from the public internet.

Step 6: Configure a Default-Deny Host Firewall (UFW or firewalld)

Configuring an on-host firewall is a foundational requirement in every Linux server hardening checklist because cloud provider security groups can be misconfigured or bypassed across private VLANs. The golden rule is simple: deny all incoming traffic by default, allow outbound traffic, and explicitly whitelist only required ports.

On Ubuntu and Debian, Uncomplicated Firewall (UFW) provides a clean front-end over iptables/nftables:

sudo apt install -y ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp comment 'SSH Access'
sudo ufw allow 80/tcp comment 'HTTP Web Traffic'
sudo ufw allow 443/tcp comment 'HTTPS Web Traffic'
sudo ufw enable
sudo ufw status verbose

On AlmaLinux, Rocky Linux, or RHEL, use firewalld to achieve the exact same posture:

sudo systemctl enable --now firewalld
sudo firewall-cmd --set-default-zone=public
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --list-all

Step 7: Deploy Fail2Ban or CrowdSec to Block Brute-Force Attacks

Automated intrusion prevention is the seventh pillar of this Linux server hardening checklist, stopping persistent bots before they consume CPU cycles, bloat authentication logs, or probe web endpoints for vulnerabilities. Intrusion prevention tools monitor log streams in real time and dynamically drop offending IPs at the firewall level.

Install Fail2Ban and create a local override file (/etc/fail2ban/jail.local) so package updates never overwrite your custom thresholds:

sudo apt install -y fail2ban
sudo tee /etc/fail2ban/jail.local > /dev/null <<'EOF'
[DEFAULT]
bantime  = 1h
findtime = 10m
maxretry = 3
backend  = systemd

[sshd]
enabled  = true
port     = ssh
mode     = aggressive
EOF

sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd

For multi-server production fleets, consider pairing or replacing Fail2Ban with CrowdSec. CrowdSec separates log parsing from remediation and shares anonymized threat intelligence across its global network, blocking known malicious scanners before they even send their first packet to your VPS.

Step 8: Audit Listening Sockets and Bind Internal Services to Localhost

Auditing active network sockets is an often-overlooked step in a Linux server hardening checklist, yet installing a database or cache service—such as PostgreSQL, MySQL, MongoDB, or Redis—and leaving it bound to 0.0.0.0 remains a leading cause of data breaches. Always inspect active listening sockets after installing any software package:

sudo ss -tulpn

Review every row in the output. Unless a service is intentionally public-facing (such as Nginx, Caddy, or OpenSSH), its local address must be restricted to 127.0.0.1, ::1, or a dedicated private VPC interface (e.g., 10.0.0.5).

Additionally, if your infrastructure does not actively route IPv6 traffic, disable IPv6 at the kernel level so firewall rules written for IPv4 do not leave an unmonitored dual-stack backdoor open.

Linux server hardening checklist network socket audit using ss -tulpn and UFW firewall rules
Auditing listening sockets with ss -tulpn is a vital Linux server hardening checklist verification step to keep databases off public interfaces.

Phase 3: Kernel, Filesystem, and Mandatory Access Control

Perimeter defenses stop external opportunistic attacks, whereas the third phase of this Linux server hardening checklist hardens the operating system core itself to contain damage if an application vulnerability is exploited.

Step 9: Harden Linux Kernel Parameters via sysctl

Kernel runtime tuning gives your Linux server hardening checklist deep network-stack resilience. The Linux kernel exposes hundreds of runtime networking and memory parameters under /proc/sys/ that mitigate TCP SYN flood attacks, prevent IP spoofing, block ICMP redirect route poisoning, and strengthen kernel memory protections.

Create a dedicated configuration file at /etc/sysctl.d/99-security-hardening.conf referencing official Linux Kernel sysctl networking documentation:

# Protect against TCP SYN flood attacks
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_synack_retries = 2

# Enable Reverse Path Filtering to block IP spoofing
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1

# Disable IP source routing and packet forwarding (unless acting as a router/VPN)
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.ip_forward = 0

# Ignore ICMP redirects and bogus error responses
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1

# Log martian packets (packets with impossible source addresses)
net.ipv4.conf.all.log_martians = 1
net.ipv4.conf.default.log_martians = 1

# Kernel memory and pointer protections
kernel.randomize_va_space = 2
kernel.kptr_restrict = 2
kernel.dmesg_restrict = 1
kernel.yama.ptrace_scope = 1
fs.protected_hardlinks = 1
fs.protected_symlinks = 1

Note that if your VPS runs Docker or acts as a WireGuard VPN gateway, keep net.ipv4.ip_forward = 1 enabled so container or tunnel routing continues functioning properly. Apply your new kernel settings immediately:

sudo sysctl --system

Step 10: Enforce Mandatory Access Control with AppArmor or SELinux

Enforcing Mandatory Access Control adds kernel-level process confinement to your Linux server hardening checklist. Standard Linux file permissions rely on Discretionary Access Control (DAC), where a web server process running as www-data can read any file owned by www-data. Mandatory Access Control (MAC) enforces strict policy confinement on top of user permissions, preventing a compromised Nginx or PHP process from reading SSH keys or modifying system binaries.

  • Ubuntu / Debian (AppArmor): Verify that AppArmor is active and profiles are in enforce mode by running sudo aa-status. Install extra community profiles via sudo apt install -y apparmor-profiles apparmor-utils.
  • AlmaLinux / Rocky Linux / RHEL (SELinux): Confirm SELinux is set to Enforcing by running getenforce. Never disable SELinux to troubleshoot a permission error; instead, inspect denials with ausearch -m avc -ts recent and assign proper file contexts using semanage fcontext and restorecon.

Step 11: Secure Shared Memory (/dev/shm) and Temporary Mounts

Hardening mount options for shared memory and temporary directories closes a common post-exploitation gap in any Linux server hardening checklist. Attackers who gain limited shell access via a web application flaw frequently upload compiled exploit binaries to world-writable directories like /tmp, /var/tmp, or shared memory (/dev/shm) and execute them from there.

You can neutralize this entire class of attacks by mounting temporary filesystems with the noexec, nosuid, and nodev flags in /etc/fstab:

tmpfs /dev/shm tmpfs defaults,noexec,nosuid,nodev 0 0

If /tmp is mounted on its own partition or tmpfs volume, apply the same flags there as well. Remount /dev/shm immediately to enforce the restriction without rebooting:

sudo mount -o remount,noexec,nosuid,nodev /dev/shm

Step 12: Audit SUID/SGID Binaries and Lock Down Cron Permissions

Privilege escalation prevention rounds out the third phase of our Linux server hardening checklist by auditing SUID/SGID binaries and locking down scheduled tasks. Binaries with the SUID (Set User ID) or SGID (Set Group ID) bit enabled execute with the privileges of the file owner—often root—regardless of who launches them. Periodically scan your filesystem for unexpected SUID/SGID executables:

sudo find / -xdev \( -perm -4000 -o -perm -2000 \) -type f -exec ls -ld {} + 2>/dev/null

Compare the output against known legitimate binaries (such as /usr/bin/sudo or /usr/bin/passwd). Remove the SUID bit (chmod u-s) from any legacy or unnecessary utility that does not require elevated execution.

Similarly, restrict access to scheduled task directories so non-privileged users cannot inspect or inject cron jobs:

sudo chown root:root /etc/crontab
sudo chmod 600 /etc/crontab
sudo chmod 700 /etc/cron.d /etc/cron.daily /etc/cron.hourly /etc/cron.monthly /etc/cron.weekly

Phase 4: Monitoring, Auditing, and Incident Readiness

No security posture is impenetrable, which is why the final phase of this Linux server hardening checklist focuses on rapid detection, forensic auditing, and disaster recovery.

Step 13: Enable Kernel-Level Auditing with auditd

Kernel-level system auditing ensures your Linux server hardening checklist captures tamper-proof forensic records. The Linux Audit Daemon (auditd) records low-level system calls, file modifications, and privilege escalations directly from the kernel, creating an immutable trail even if an attacker clears bash history.

Install auditd and configure watch rules for high-value identity and configuration files:

sudo apt install -y auditd audispd-plugins

sudo tee /etc/audit/rules.d/99-hardening.rules > /dev/null <<'EOF'
# Monitor changes to user and group databases
-w /etc/passwd -p wa -k identity_changes
-w /etc/group -p wa -k identity_changes
-w /etc/shadow -p wa -k identity_changes
-w /etc/sudoers -p wa -k privilege_escalation
-w /etc/sudoers.d/ -p wa -k privilege_escalation

# Monitor OpenSSH configuration modifications
-w /etc/ssh/sshd_config -p wa -k sshd_config_changes
-w /etc/ssh/sshd_config.d/ -p wa -k sshd_config_changes

# Monitor system time changes and kernel module loading
-a always,exit -F arch=b64 -S adjtimex -S settimeofday -k time_change
-w /sbin/insmod -p x -k kernel_modules
-w /sbin/modprobe -p x -k kernel_modules
EOF

sudo augenrules --load
sudo systemctl enable --now auditd

Step 14: Configure File Integrity Monitoring (AIDE)

File Integrity Monitoring (FIM) adds automated change detection to this Linux server hardening checklist by creating a cryptographic hash baseline of critical system binaries, libraries, and configuration files while your VPS is in a known clean state. If a rootkit or attacker later replaces /usr/sbin/sshd or injects code into system libraries, your daily integrity check immediately flags the checksum mismatch.

sudo apt install -y aide
sudo aideinit
sudo cp /var/lib/aide/aide.db.new /var/lib/aide/aide.db

Schedule a daily cron job or systemd timer running aide --check and piping alerts to your operations inbox or Slack webhook. Remember to update the AIDE database after planned system upgrades so legitimate package updates do not trigger false alarms.

Step 15: Automate Encrypted Off-Site Backups and Remote Log Shipping

A production-grade Linux server hardening checklist is incomplete without immutable disaster recovery and off-host log retention. Local snapshots stored on the same VPS block volume offer zero protection against account compromise, ransomware, or storage node failure.

  • Encrypted Off-Site Backups: Follow the 3-2-1 backup rule using deduplicating, client-side encrypted tools such as Restic or BorgBackup. Push encrypted snapshots nightly to an S3-compatible object storage bucket (such as Cloudflare R2, Backblaze B2, or AWS S3) with Object Lock enabled so even compromised server credentials cannot delete historical backups.
  • Centralized Log Forwarding: Configure rsyslog, Vector, or Promtail to stream authentication and kernel audit logs to an external log aggregator in real time. Off-host log retention preserves forensic evidence even if an intruder attempts to wipe /var/log/ locally.
Linux server hardening checklist auditd logging, AIDE file integrity, and encrypted off-site backup architecture
Streaming auditd logs off-host and pushing encrypted backups to immutable object storage completes this Linux server hardening checklist.

Post-Hardening Verification: Auditing Your VPS with Lynis

After completing all 15 steps on your Linux server hardening checklist, run an automated security audit to measure your posture and catch any overlooked edge cases. Lynis is an open-source security auditing tool widely used by DevOps teams to evaluate Unix-based systems against compliance standards.

sudo apt install -y lynis
sudo lynis audit system

Lynis inspects hundreds of configuration parameters across authentication, kernel hardening, storage, networking, and installed software, generating a concrete Hardening Index score (typically 75–85+ on a properly hardened VPS) along with actionable warnings and suggestions. Re-run Lynis quarterly—or bake this entire Linux server hardening checklist directly into your Terraform, Ansible, or cloud-init provisioning pipeline—so every newly launched server inherits this hardened baseline automatically.

Frequently Asked Questions About Linux Server Hardening

How long does it take to complete this Linux server hardening checklist?

Executing these 15 steps manually on a fresh VPS takes roughly 30 to 45 minutes. Once verified, you can codify the entire workflow into an Ansible playbook or cloud-init script, reducing provisioning time for future production servers to under two minutes.

Should I change the default SSH port from 22 to a custom port?

While changing the SSH port is optional in our Linux server hardening checklist, moving SSH off port 22 dramatically reduces automated background log noise from unsophisticated bots. Just remember that port obfuscation is not a substitute for SSH keys, a firewall, or Fail2Ban, because determined attackers running full port scans will still locate custom ports.

Does server hardening negatively impact application performance?

No. Almost every control in this Linux server hardening checklist—including SSH key enforcement, UFW firewall rules, and sysctl networking tweaks—adds negligible overhead while actually improving stability under load by dropping malicious traffic early in the network stack. The only noticeable overhead comes from scheduled AIDE file scans, which should run during low-traffic off-peak hours.

What is the difference between UFW, iptables, and nftables?

Every Linux server hardening checklist relies on packet filtering, and understanding the underlying tools prevents rule conflicts. iptables and its modern successor nftables are the underlying Linux kernel packet-filtering frameworks that inspect and drop network traffic, whereas UFW (Uncomplicated Firewall) on Debian/Ubuntu and firewalld on RHEL-based systems are user-friendly management front-ends that translate simple rules into underlying nftables rulesets.

Building a Repeatable Security Baseline

Securing a production Linux VPS is never a single set-and-forget event, yet starting from a disciplined foundation eliminates the overwhelming majority of real-world attack vectors. By locking down SSH authentication, enforcing default-deny firewalling, tuning kernel protections, and automating encrypted off-site backups, you transform a vulnerable default cloud instance into resilient production infrastructure.

Bookmark this Linux server hardening checklist for your next server rollout, convert these commands into your team’s configuration management templates, and schedule regular audits so your security posture scales alongside your workloads.