
This article demonstrates how to harden security of VPS server and is intended for server administrators.
Ultimate Guide to Harden Security of a VPS Server
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 hardening steps used by experienced system administrators, from the first login to long-term monitoring and incident readiness.
How to Harden Security of VPS Server
To harden security of VPS server, follow the steps outlined below:
-
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
-
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
- Debian/Ubuntu:
-
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
-
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
-
Install Intrusion Prevention (Fail2Ban)
Fail2Ban blocks IPs that attempt brute-force attacks.
# Debian / Ubuntu apt install fail2ban -y # RHEL-based dnf install epel-release -y dnf install fail2ban -y
Create
/etc/fail2ban/jail.local:[sshd] enabled = true port = 2222 maxretry = 3 bantime = 1h
Restart:
systemctl restart fail2ban
-
Enforce Strong User & Permission Controls
Disable unnecessary users
awk -F: '$3 >= 1000 {print $1}' /etc/passwdRemove unused accounts:
userdel username
Use sudo (not root)
Read: How to Use Sudo
usermod -aG wheel admin
Audit sudo usage:
grep sudo /var/log/auth.log
-
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
-
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
-
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
- Logwatch
- Netdata
- Prometheus + Grafana
- Wazuh / OSSEC
-
Backups Are Security
A hacked server without backups is a catastrophe.
- 3 copies of data
- 2 different storage types
- 1 offsite (object storage, remote server)
Test restores regularly.
-
Malware & Rootkit Detection
Install scanners:
apt install rkhunter chkrootkit -y
Schedule weekly scans:
rkhunter --update && rkhunter --check
-
Encrypt Everything
- Use TLS certificates (Let’s Encrypt)
- Encrypt backups
- Encrypt sensitive config files
- Use secrets managers where possible
-
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.
Conclusion
You now know how to harden security of VPS server.









