Your new VPS just booted: a fresh operating system, a root account, and SSH open to the entire internet on port 22. Give it a few hours and automated scanners will find it. They probe every new server relentlessly, trying common usernames and weak passwords, because thousands of servers like yours sit exposed at any moment. The cheapest time to secure a server is before anything valuable is on it, so run through these ten steps before you deploy a single app.
1. Update the operating system
VPS images ship slightly out of date, and old packages with known vulnerabilities are the easiest thing to exploit. On your very first login, bring everything current:
apt update && apt full-upgrade -y
If the upgrade installed a new kernel, reboot with reboot. A server that restarts cleanly today is one you can trust to restart after a 3 a.m. patch next month. Do this on Debian or Ubuntu systems; on RHEL-family servers use dnf upgrade -y instead.
2. Create a non-root user with sudo
Working as root every day is a liability. One typo in a destructive command runs with full privileges, and every password-guessing script on the internet already knows the username. Create a normal user and grant it sudo:
adduser deploy
usermod -aG sudo deploy
Pick a username that is not obvious. You will log in as this user from now on and only reach for root through sudo when you actually need it.
3. Switch to SSH key authentication
Passwords are the weak point scanners attack. Keys are stronger and far more convenient once they are set up. From your own machine, generate a key pair if you do not have one:
ssh-keygen -t ed25519 -C “your-laptop”
Then copy the public key to the new user on the server:
ssh-copy-id deploy@YOUR_SERVER_IP
Log in once with ssh deploy@YOUR_SERVER_IP to confirm the key works before touching the SSH configuration. If you get in without a password prompt, you are ready for the next step.
4. Disable password and root SSH logins
Open /etc/ssh/sshd_config on the server and set these two lines:
PasswordAuthentication no
PermitRootLogin no
Apply the change with systemctl reload sshd. Open a second terminal and start a fresh SSH connection before closing your first one. If anything is wrong, the first session is still alive and you can fix it. A locked-out server with no key access means opening your provider’s console, which is slow and painful.
One honest note about changing the SSH port: moving from port 22 to a custom port cuts the spam in your auth logs, but it adds no real security. Do it if log noise bothers you, not as a substitute for key authentication.
5. Turn on the firewall
Ubuntu and Debian ship UFW, a simple front end for iptables. Block everything incoming by default and open only what you need:
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw enable
If you run SSH on a custom port, allow that port instead of 22. Add ports 80 and 443 only when you actually deploy a web server, not before. Verify the rules with ufw status verbose.
6. Install fail2ban
Even with keys and a firewall, scanners will hammer your SSH port forever. Fail2ban watches the auth log and temporarily bans IPs that fail too many logins. Install it and add a small local config:
apt install fail2ban -y
Create /etc/fail2ban/jail.local with these lines:
[sshd] enabled = true maxretry = 5 findtime = 10m bantime = 1h
Then systemctl enable –now fail2ban. Check it is working with fail2ban-client status sshd. Five failed logins within ten minutes now earns the attacker a one-hour ban.
7. Enable automatic security updates
The most common way small servers get compromised is a patched vulnerability that never got applied. Let the system install security updates itself:
apt install unattended-upgrades -y
dpkg-reconfigure -plow unattended-upgrades
Answer yes at the prompt. The default configuration pulls security updates daily, which covers the critical window. If your provider supports live patching or you can tolerate a reboot window, configure automatic reboots too — an unpatched kernel is only patched after a restart.
8. Audit what is listening
Every open port is an attack surface. Check which services are listening on your server:
ss -tulnp
Look for anything you did not expect. A fresh VPS should show SSH and little else. If you see a database or mail service you never installed, investigate before you continue. Disable anything unnecessary with:
systemctl disable –now unwanted-service
Run this audit again after every major software installation. Services have a way of appearing that you did not ask for.
9. Apply basic kernel hardening
A few sysctl settings raise the bar for common attack techniques like IP spoofing and SYN floods. Create /etc/sysctl.d/99-hardening.conf:
net.ipv4.conf.all.rp_filter = 1
net.ipv4.tcp_syncookies = 1
kernel.dmesg_restrict = 1
Apply with sysctl –system. These settings are conservative, reversible, and safe for typical VPS workloads. They are not a replacement for the steps above, but they cost nothing and close real holes.
10. Set up backups before you need them
This is the step people skip and regret the most. Two layers beat one: a provider snapshot for fast full-disk recovery, and an offsite copy of your important data for when the provider itself has a bad day. A daily rsync of your data directories to another server or object storage takes minutes to script and saves entire businesses.
The rule that matters: test a restore once. A backup you have never restored is a hope, not a backup. Write down where the backups live, how to restore them, and what the retention period is.
Quick-reference checklist
| Step | Action | Approx. time |
|---|---|---|
| 1 | Update the OS and reboot | 5 minutes |
| 2 | Create a non-root sudo user | 3 minutes |
| 3 | Set up SSH key authentication | 5 minutes |
| 4 | Disable password and root SSH logins | 5 minutes |
| 5 | Enable the UFW firewall | 3 minutes |
| 6 | Install and configure fail2ban | 5 minutes |
| 7 | Enable automatic security updates | 3 minutes |
| 8 | Audit listening services | 5 minutes |
| 9 | Apply kernel hardening settings | 5 minutes |
| 10 | Set up and test backups | 20 minutes |
Keep it secure after day one
Security is a habit, not a one-time setup. Once a week, spend five minutes on these:
- Check /var/log/unattended-upgrades/ to confirm security updates actually installed.
- Look at fail2ban-client status sshd for a sense of how much scanning you absorb.
- Run ss -tulnp after any new installation to catch new listeners.
- Verify your last backup completed and still restores.
About an hour of setup buys you a server you can actually trust. Do these ten steps once, keep the weekly habit, and your VPS will be far harder to compromise than most of what the scanners find out there. Once the basics are done, the same hardened box can run your first real projects, starting with a Jellyfin media server in Docker.