...
Ultimate guide to vps security hardening
Ultimate guide to vps security hardening

This article provides a guide to VPS security hardening.

Securing a Virtual Private Server (VPS) is not a one-time task—it’s an ongoing discipline. Whether you’re hosting websites, applications, databases, or client workloads, a hardened VPS dramatically reduces the risk of compromise, data loss, downtime, and reputation damage.

This guide walks through practical, production-grade VPS security hardening steps used by experienced system administrators, from the first login to long-term monitoring and incident readiness.

Launch 100% ssd vps from $3. 19/mo!

Ultimate Guide to VPS Security Hardening

  1. Start With a Clean, Minimal OS

    Security begins before the server ever goes online.

    Best practices

    • Use a fresh OS image (AlmaLinux, Rocky Linux, Debian, Ubuntu LTS).
    • Avoid preinstalled “application stacks” unless you fully trust and audit them.
    • Choose LTS releases for long-term security updates.
    • Remove unused packages immediately after provisioning.
    # Debian / Ubuntu
    apt purge telnet ftp rsh rlogin xinetd -y
    
    # RHEL-based
    dnf remove telnet ftp rsh rlogin xinetd -y
    
  2. Keep the System Fully Updated

    Unpatched servers are one of the most common breach vectors.

    Immediate actions

    # Debian / Ubuntu
    apt update && apt upgrade -y
    
    # AlmaLinux / Rocky
    dnf update -y
    

    Enable automatic security updates

    • Debian/Ubuntu: unattended-upgrades
    • RHEL-based: dnf-automatic
  3. Lock Down SSH Access

    SSH is the front door to your VPS—protect it aggressively.

    Change SSH defaults

    Edit /etc/ssh/sshd_config:

    Port 2222
    PermitRootLogin no
    PasswordAuthentication no
    PubkeyAuthentication yes
    AllowUsers deploy admin
    

    Restart SSH:

    systemctl restart sshd
    

    Use SSH keys only

    Generate keys locally:

    ssh-keygen -t ed25519
    

    Upload the public key to:

    ~/.ssh/authorized_keys
    
  4. Configure a Firewall (Mandatory)

    A firewall ensures only explicitly allowed traffic reaches your VPS.

    UFW (Ubuntu/Debian)

    ufw default deny incoming
    ufw default allow outgoing
    ufw allow 2222/tcp
    ufw allow 80/tcp
    ufw allow 443/tcp
    ufw enable
    

    firewalld (Alma/Rocky)

    firewall-cmd --set-default-zone=drop
    firewall-cmd --permanent --add-service=ssh
    firewall-cmd --permanent --add-service=http
    firewall-cmd --permanent --add-service=https
    firewall-cmd --reload
    
  5. Install Intrusion Prevention (Fail2Ban)

    Fail2Ban blocks IPs that attempt brute-force attacks.

    apt install fail2ban -y
    

    Create /etc/fail2ban/jail.local:

    [sshd]
    enabled = true
    port = 2222
    maxretry = 3
    bantime = 1h
    

    Restart:

    systemctl restart fail2ban
    
  6. Enforce Strong User & Permission Controls

    Disable unnecessary users

    awk -F: '$3 >= 1000 {print $1}' /etc/passwd
    

    Remove unused accounts:

    userdel username
    

    Use sudo (not root)

    usermod -aG wheel admin
    

    Audit sudo usage:

    grep sudo /var/log/auth.log
    
  7. Harden Kernel & Network Settings (sysctl)

    Edit /etc/sysctl.conf:

    net.ipv4.conf.all.rp_filter=1
    net.ipv4.conf.default.rp_filter=1
    net.ipv4.icmp_echo_ignore_broadcasts=1
    net.ipv4.tcp_syncookies=1
    net.ipv4.conf.all.accept_source_route=0
    net.ipv4.conf.all.accept_redirects=0
    net.ipv4.conf.all.send_redirects=0
    

    Apply:

    sysctl -p
    
  8. Secure Services & Applications

    Web servers

    • Remove version headers
    • Enable security headers
    • Disable directory listing

    Example (Nginx):

    server_tokens off;
    add_header X-Frame-Options SAMEORIGIN;
    add_header X-Content-Type-Options nosniff;
    add_header X-XSS-Protection "1; mode=block";
    

    Databases

    • Bind to 127.0.0.1
    • Enforce strong passwords
    • Remove anonymous users
    mysql_secure_installation
    
  9. Log, Monitor, and Alert

    Essential logs

    • /var/log/auth.log
    • /var/log/secure
    • /var/log/nginx/access.log
    • /var/log/nginx/error.log

    Tools to consider

  10. Backups Are Security

    A hacked server without backups is a catastrophe.

    Follow the 3-2-1 rule

    • 3 copies of data
    • 2 different storage types
    • 1 offsite (object storage, remote server)

    Test restores regularly.

  11. Malware & Rootkit Detection

    Install scanners:

    apt install rkhunter chkrootkit -y
    

    Schedule weekly scans:

    rkhunter --update && rkhunter --check
    
  12. Encrypt Everything

    • Use TLS certificates (Let’s Encrypt)
    • Encrypt backups
    • Encrypt sensitive config files
    • Use secrets managers where possible
  13. Prepare for Incidents

    Have a plan before something goes wrong:

    • Snapshot immediately
    • Rotate credentials
    • Check persistence mechanisms
    • Audit logs
    • Rebuild from clean backups if needed

Final Security Checklist

✔ Minimal OS
✔ Automatic updates
✔ SSH key-only access
✔ Firewall enabled
✔ Fail2Ban active
✔ Least privilege users
✔ Kernel hardening
✔ Secured services
✔ Monitoring & alerts
✔ Offsite backups
✔ Malware scanning
✔ Encryption everywhere

Closing Thoughts

A VPS is only as secure as the discipline behind it. Most compromises don’t happen because attackers are brilliant—they happen because basic hardening steps were skipped.

Treat security as a process, not a checkbox, and your VPS will remain fast, stable, and trustworthy long-term.

Launch 100% ssd vps from $3. 19/mo!

Conclusion

You now crucial steps to achieve VPS security hardening.

Avatar of editorial staff

Editorial Staff

Rad Web Hosting is a leading provider of web hosting, Cloud VPS, and Dedicated Servers in Dallas, TX.
lg