- SSH Key Enforcement:Mandate Ed25519 SSH keys, disable root password login, and enforce modern cryptographic ciphers (ChaCha20-Poly1305 / AES-256-GCM).
- Kernel Network Hardening:Configuresysctlto block TCP SYN floods, IP source routing, ICMP redirects, and reverse path spoofing.
- Firewall & Rate Limiting:Implement Uncomplicated Firewall (UFW) with default-deny inbound rules and SSH brute-force rate limits.
- Automated Intrusion Prevention:Deployfail2banandauditdfor continuous log analysis and kernel event tracking.
1. Threat Modeling & Initial Attack Surface Reduction
Deploying a virtual private server (VPS) on cloud infrastructure immediately places the machine in an active adversarial environment. Public IPv4 and IPv6 subnets are continuously scanned by automated botnets and distributed threat actors executing reconnaissance, dictionary attacks, and known vulnerability probes within seconds of provisioning.
Minimizing initial attack surface requires establishing strict zero-trust baselines from initial boot. Every unnecessary service, open network daemon, and legacy protocol must be completely removed. Administrators must disable default password-based authentication immediately and migrate administrative ingress away from standard port 22 to high-range unassigned TCP ports.
By replacing password-based access with elliptic curve cryptography (Ed25519) and enforcing hardware-bound MFA tokens, organizations neutralize 99.9% of automated credential stuffing attacks.
Hardened SSH and kernel sysctl parameters can be generated automatically using our interactive Linux Hardening Config Builder to eliminate guesswork and standardize defense profiles across cloud fleets.
# Disable root login and enforce Ed25519 key authentication
sudo sed -i -E "s/^#?PermitRootLogin .*/PermitRootLogin no/" /etc/ssh/sshd_config
sudo sed -i -E "s/^#?PasswordAuthentication .*/PasswordAuthentication no/" /etc/ssh/sshd_config
sudo sed -i -E "s/^#?Port .*/Port 2222/" /etc/ssh/sshd_config
sudo systemctl restart sshd
2. User Privilege Separation & PAM Account Lockout Hardening
Operating a production Linux server under the root account is a catastrophic anti-pattern. System administrators must create dedicated, unprivileged user accounts with restricted sudo capabilities bound to specific operational binaries.
Pluggable Authentication Modules (PAM) provide the operating system authentication gateway. Without explicit rate limiting, attackers can launch distributed dictionary attacks against local PAM authentication stacks. Modern Linux distributions rely on pam_faillock to track and lock abusing accounts.
Configuring pam_faillock with strict thresholds (e.g. 3 consecutive failed attempts leading to a 15-minute lockout period) guarantees that brute-force velocity is reduced to zero.
Administrators should generate standardized faillock configurations via our PAM Faillock Config Generator to defend auth endpoints reliably.
# /etc/security/faillock.conf
dir = /var/run/faillock
audit
silent
denytick = 3
unlock_time = 900
fail_interval = 900
3. Kernel Sysctl Hardening & Network Stack Security
The Linux kernel network stack defaults to broad compatibility across legacy networking topologies rather than defensive isolation. Attackers exploit default network configurations through IP spoofing, TCP SYN floods, ICMP redirect poisoning, and packet routing manipulation.
Applying hardened sysctl directives in /etc/sysctl.d/ creates a resilient transport layer. Enforcing strict Reverse Path Filtering (rp_filter = 1) prevents source IP address spoofing by dropping packets whose ingress interface differs from the expected routing return path.
Enabling TCP SYN Cookies (tcp_syncookies = 1) ensures the kernel can survive intense volumetric connection floods without exhausting finite syn-backlog memory buffers.
Network CIDR blocks and IP mask ranges can be validated alongside our Subnet & CIDR Calculator during firewall provisioning.
# /etc/sysctl.d/99-security-hardening.conf
net.ipv4.tcp_syncookies = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv6.conf.all.disable_ipv6 = 1
4. Stateful Firewalling & Automated Intrusion Prevention
A stateful firewall is mandatory for any internet-facing VPS. Uncomplicated Firewall (UFW) and nftables provide deterministic packet filtering engines that enforce default-deny incoming postures while allowing authorized stateful outbound communication.
Pairing stateful packet filters with automated intrusion prevention engines like Fail2ban or CrowdSec provides adaptive defense. When suspicious probes or repetitive authentication failures are detected in systemd journald logs, the engine dynamically injects ephemeral firewall drop rules at the kernel filter level.
This automated behavioral blacklisting isolates compromised bots before they can identify vulnerable secondary endpoints.
Compare config diffs and verify rule order using the Diff Checker Tool to prevent accidental lockout.
# Configure UFW default deny and allow SSH
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 2222/tcp comment "Hardened SSH Port"
sudo ufw enable
5. Kernel Event Auditing (Auditd) & Threat Hunting
Passive defensive configurations must be coupled with continuous runtime auditing. Standard application loggers can be bypassed or deleted by attackers who achieve local privilege escalation. In contrast, the Linux Audit Subsystem (auditd) hooks system calls directly at the kernel boundary.
File Integrity Monitoring (FIM) watches critical operating system paths (/etc/passwd, /etc/shadow, /etc/sudoers, /etc/ssh/sshd_config) and logs any write, read, or permission modifications with immutable cryptographic context.
Locking audit rules in memory with the immutable flag (-e 2) prevents unauthorized rule tampering until the physical node undergoes a system reboot.
Generate tailored audit rules with our dedicated Auditd Rule Generator.
# Watch critical identity and permission files
-w /etc/passwd -p wa -k identity_modification
-w /etc/shadow -p wa -k password_tamper
-w /etc/sudoers -p wa -k privilege_escalation
-e 2
6. Unattended Security Upgrades & Production Verification
The vast majority of server compromises exploit known, patched vulnerabilities where administrators delayed system upgrades. Automated unattended upgrades ensure critical security patches for OpenSSL, OpenSSH, and kernel components are applied within hours of release.
Configuring unattended-upgrades with automatic reboot windows during off-peak maintenance hours minimizes production impact while guaranteeing zero window-of-exposure vulnerabilities.
Verify system security post-deployment by auditing open ports and validating TLS cipher suites.
Run empirical verification and check TLS cipher configurations with the Curl Command Builder.
# /etc/apt/apt.conf.d/50unattended-upgrades
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}-security";
};
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "03:30";
Frequently Asked Questions (FAQ)
Why should I disable password authentication in SSH?
Password authentication is vulnerable to automated dictionary and brute-force attacks across public IP ranges. Ed25519 cryptographic key authentication eliminates password guessing entirely.
How does kernel sysctl tuning protect against SYN flood attacks?
Enablingnet.ipv62.tcp_syncookies = 1allows the Linux kernel to send cryptographic SYN cookies when the connection backlog queue overflows, preventing memory exhaustion attacks without dropping legitimate connection attempts.
Should I change the default SSH port 22?
While changing port 22 is security through obscurity, it eliminates up to 99% of noisy automated port-scanning bot scripts from cluttering your system authentication logs.
Utility Security Tools Related to this Article:
Gunakan Generate Hardening Configs -> untuk membantu alur kerja konfigurasi keamanan Anda secara privasi di browser.