To secure a new VPS, update the system, create a non-root user, switch SSH to key-only login, turn on a firewall, install brute-force protection, enable automatic security updates, and set up off-server backups. Those steps take under an hour and block the vast majority of automated attacks that hit every new server within minutes of going online.
A fresh VPS with a public IP address starts receiving login attempts almost immediately. Bots scan the whole internet for weak passwords and outdated software all day long. This checklist walks you through hardening an Ubuntu or Debian server step by step, with notes for AlmaLinux and Rocky Linux, and the exact commands to run.
Before You Start
- Have your server’s IP address and root password (or SSH key) from your welcome email.
- Keep the provider’s console or VNC access handy. If you lock yourself out of SSH, that’s how you get back in.
- Do the SSH changes in a second terminal window and keep your first session open until you’ve tested the new login.
apt with dnf, use firewalld instead of UFW, and use the wheel group instead of sudo.The 12-Step VPS Hardening Checklist
1. Update everything
Your OS image may be weeks old. Install all pending updates first.
apt update && apt upgrade -y
reboot
2. Set the hostname and time zone
Correct time matters for logs, SSL certificates and two-factor codes.
hostnamectl set-hostname server1.yourdomain.com
timedatectl set-timezone UTC
3. Create a non-root user with sudo
Day-to-day work should never happen as root.
adduser deploy
usermod -aG sudo deploy
4. Set up SSH key login
On your own computer, create a key (if you don’t have one) and copy it to the server:
ssh-keygen -t ed25519
ssh-copy-id deploy@YOUR_SERVER_IP
Then confirm you can log in as deploy without a password before moving on.
5. Lock down SSH
Create /etc/ssh/sshd_config.d/00-hardening.conf with the settings below. SSH uses the first value it reads, and the 00- prefix makes sure your file wins over cloud-image defaults (such as 50-cloud-init.conf, which often re-enables passwords).
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
Test the config, then restart SSH. On Ubuntu the service is called ssh; on AlmaLinux and Rocky it’s sshd.
sshd -t && systemctl restart ssh
Changing the SSH port (for example to 2222) is optional. It doesn’t stop a targeted attacker, but it cuts log noise from bots. If you change it, open the new port in the firewall first.
6. Turn on the firewall
Allow only what you use. For a typical web server:
ufw default deny incoming
ufw default allow outgoing
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
If you plan to install cPanel, it ships its own firewall setup. Most admins use CSF there instead of UFW.
7. Block brute-force attempts with Fail2ban
apt install fail2ban -y
systemctl enable --now fail2ban
The default SSH jail bans IPs after repeated failed logins. Check it with fail2ban-client status sshd.
8. Turn on automatic security updates
apt install unattended-upgrades -y
dpkg-reconfigure --priority=low unattended-upgrades
On AlmaLinux/Rocky, use dnf-automatic with security updates enabled.
9. Remove what you don’t need
Every running service is a possible way in. List what’s listening and stop anything you don’t recognize or need:
ss -tulpn
10. Secure your applications
- Use HTTPS everywhere with free Let’s Encrypt certificates (Certbot).
- Bind databases (MySQL/MariaDB, Redis) to
127.0.0.1unless something remote genuinely needs them. - Never run web apps as root. Use a dedicated user per app.
11. Set up off-server backups
A backup on the same VPS dies with the VPS. Use a tool like restic or borg to send encrypted backups to separate storage, and test a restore at least once.
12. Monitor and review
- Set up a free uptime monitor that alerts you when the site goes down.
- Check
journalctl -u sshandfail2ban-client statusweekly. - Watch disk space with
df -h. Full disks break databases and mail.
Security isn’t a one-time job. Ten minutes a week of checking updates, backups and logs keeps a hardened server hardened.
Quick Reference: What Each Step Protects Against
| Step | Protects against |
|---|---|
| SSH keys, no root login | Password guessing and credential stuffing |
| Firewall | Exposed databases, admin panels and unused services |
| Fail2ban | Repeated brute-force attempts |
| Automatic updates | Known vulnerabilities in outdated packages |
| Off-server backups | Ransomware, mistakes, disk failure |
| Monitoring | Problems you’d otherwise discover from angry users |
Privacy Extras for Offshore Servers
- Manage sensitive servers through a VPN, so your home IP doesn’t appear in SSH logs.
- Keep server logs only as long as you need them. Configure
logrotateand journald retention. - Don’t reuse SSH keys between personal and anonymous projects.
For the full picture, read our offshore VPS guide and anonymous hosting checklist.
Don’t Want to Do This Yourself?
Full disclosure: this is our blog. Every iWebVault offshore VPS is fully managed. Our team handles the hardening, updates, firewall, monitoring and emergency response in this checklist for you, and you keep full root access. Licenses for cPanel/WHM or DirectAdmin, Softaculous, Imunify360, LiteSpeed and WHMCS are included free, and we install and maintain them. Plans start at $40/mo. Not sure what “managed” covers? Read managed vs unmanaged VPS.
Frequently Asked Questions
Update all packages, then set up SSH key login and disable password authentication. Those two steps remove the most common way new servers get compromised.
It’s optional. It reduces automated login attempts in your logs, but real security comes from key-only authentication and a firewall. If you change it, allow the new port in your firewall before restarting SSH.
UFW is simple and ideal for plain Ubuntu/Debian servers. CSF is the usual choice on cPanel and DirectAdmin servers because it integrates with those panels and includes login failure detection.
Use the VNC or console access in your hosting client area to log in directly, then fix the SSH or firewall setting. If console access isn’t available, open a support ticket.
For a single-purpose server, good hardening matters more. If you host many websites or accept uploads, a malware scanner such as ClamAV, Maldet or Imunify360 is worth adding.
Skip the checklist: we secure it for you
Fully managed offshore VPS with full root, plus free cPanel/DirectAdmin, Imunify360, LiteSpeed and WHMCS licenses. Hardened and monitored by our team. From $40/mo.