Securing the SSH Attack Surface
Transitioning to Ed25519 Keys
ssh-keygen -t ed25519 -a 100 -C "[email protected]"ssh-copy-id -i ~/.ssh/id_ed25519.pub user@your-server-ipHardening sshd_config
/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]systemctl restart sshdDynamic Perimeter Defense with Fail2ban
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 = 600systemctl enable --now fail2banMitigating Zero-Day Exploits
Principle of Least Privilege and Filesystem Permissions
| Service | System User | Document Root Ownership |
|---|---|---|
| Nginx | www-data | root:www-data (read-only for app) |
| PHP-FPM | php-pool-app | app-user:www-data (writable uploads only) |
| Node.js | nodeapp | nodeapp:nodeapp (isolated runtime) |
find /var/www/html -type d -exec chmod 750 {} +
find /var/www/html -type f -exec chmod 640 {} +
chmod -R 770 /var/www/html/storageApplication Sandboxing with Systemd
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=~@privilegedKernel Hardening via Sysctl
/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 = 2sysctl --systemAutomated Vulnerability Management and Unattended Upgrades
apt install unattended-upgrades/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";dpkg-reconfigure -plow unattended-upgrades