Bali, Indonesia
Insights

Hardening Linux Web Servers Against SSH Brute Force and Zero-Day Exploits

October 12, 2026
As infrastructure engineers managing public-facing Linux web servers, we face a relentless stream of automated scanners, credential stuffing bots, and opportunistic exploit kits. The moment a fresh IP address is provisioned and assigned to a public interface, SSH brute-force attacks begin within minutes. While SSH is inherently secure when configured correctly, default configurations on many Linux distributions leave room for compromise. Coupled with the looming threat of zero-day vulnerabilities in web applications and system packages, building a resilient hosting environment requires a defense-in-depth posture. In this technical guide, we will break down the essential steps to harden your Linux web servers against unauthorized SSH access and mitigate the impact of unforeseen zero-day exploits using modern kernel features, granular access controls, and strict resource isolation.
Securing Secure Shell (SSH) is the absolute baseline of server administration. Relying solely on passwords is a critical vulnerability given the velocity of modern botnets equipped with massive credential dictionaries.
Legacy RSA keys are increasingly vulnerable to side-channel attacks and require long key lengths for adequate security. Ed25519, based on Edwards-curve Digital Signature Algorithm, offers superior performance and security with much shorter keys. Generate a secure key pair on your local machine:
ssh-keygen -t ed25519 -a 100 -C "[email protected]"
Copy your public key to the remote server:
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@your-server-ip
With your key deployed, lock down the SSH daemon configuration located at /etc/ssh/sshd_config (or split configuration files under /etc/ssh/sshd_config.d/). Modify the following directives to enforce strict cryptographic and access standards:
# Disable root login entirely
PermitRootLogin no

# Enforce public key authentication
PasswordAuthentication no
PubkeyAuthentication yes
ChallengeResponseAuthentication no

# Restrict allowed users
AllowUsers admin-deployer

# Optimize connection timeouts to drop stale sessions
ClientAliveInterval 300
ClientAliveCountMax 2

# Restrict strong ciphers and MACs only
Ciphers [email protected],[email protected]
KexAlgorithms curve25519-sha256,[email protected]
MACs [email protected]
Restart the SSH service to apply changes:
systemctl restart sshd
Even with password authentication disabled, repeated unauthorized connection attempts consume system file descriptors and log storage. Installing and configuring fail2ban mitigates volumetric scanning by dynamically updating firewall rules to ban offending IPs. Create a local jail configuration at /etc/fail2ban/jail.local:
[sshd]
enabled = true
port = ssh
logpath = %(sshd_log)s
backend = systemd
maxretry = 3
bantime = 86400
findtime = 600
Enable and start the service:
systemctl enable --now fail2ban
While hardening SSH protects the management plane, zero-day vulnerabilities in the Linux kernel, web servers, or runtime environments (like PHP or Node.js) pose an existential threat. Because a zero-day vulnerability by definition has no immediate patch, our mitigation strategy must focus on containing the blast radius.
Never run web applications under privileged user accounts such as root. Ensure that web services run under dedicated, unprivileged system users with restricted shell access.
ServiceSystem UserDocument Root Ownership
Nginxwww-dataroot:www-data (read-only for app)
PHP-FPMphp-pool-appapp-user:www-data (writable uploads only)
Node.jsnodeappnodeapp:nodeapp (isolated runtime)
Enforce restrictive file permissions across your document roots:
find /var/www/html -type d -exec chmod 750 {} +
find /var/www/html -type f -exec chmod 640 {} +
chmod -R 770 /var/www/html/storage
Modern systemd allows you to apply strict containment policies to services without needing complex containerization frameworks. You can isolate system daemons by adding hardening directives to their systemd service overrides (systemctl edit nginx). Example hardening flags for an application service:
[Service]
# Protect system directories from modification
ProtectSystem=strict
ProtectHome=true

# Restrict network access if the service does not require it
PrivateNetwork=false

# Prevent privilege escalation via setuid/setgid binaries
NoNewPrivileges=true

# Hide other users' processes
ProtectProc=invisible

# Restrict kernel system calls
SystemCallArchitectures=native
SystemCallFilter=@system-service
SystemCallFilter=~@privileged
Tune your Linux kernel networking and memory parameters in /etc/sysctl.d/99-security-hardening.conf to protect against common network-layer attacks and memory exploitation techniques:
# Disable IP source routing
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0

# Enable TCP SYN cookies to mitigate SYN flood attacks
net.ipv4.tcp_syncookies = 1

# Ignore ICMP redirects to prevent routing table tampering
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0

# Enable Randomized Layout of Virtual Address Space (ASLR)
kernel.randomize_va_space = 2

# Restrict access to kernel logs and debugging information
kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
Apply the changes immediately without rebooting:
sysctl --system
Zero-day exploits are frequently patched by upstream maintainers within hours of public disclosure. Automating security updates ensures your systems ingest critical patches rapidly. Install the unattended-upgrades package on Debian/Ubuntu systems:
apt install unattended-upgrades
Configure /etc/apt/apt.conf.d/50unattended-upgrades to automatically apply security patches while filtering out unstable or major releases:
Unattended-Upgrade::Allowed-Origins {
    "${distro_id}:${distro_codename}-security";
};
Unattended-Upgrade::Automatic-Reboot "false";
Enable the upgrade timer:
dpkg-reconfigure -plow unattended-upgrades
Security is not a static configuration checklist, but an ongoing process of risk reduction and defense-in-depth engineering. By eliminating password-based authentication for SSH, deploying dynamic perimeter filters, isolating services via systemd, and ensuring rapid automated patching, you drastically raise the cost of compromise for malicious actors. Combine these technical safeguards with rigorous log aggregation and monitoring to maintain full visibility over your hosting infrastructure.