01
Before you start, then update
Two precautions before you touch anything:
- find your VPS's console in the customer area: it gives you control of the machine even when SSH no longer responds. It's your safety net if something goes wrong;
- create a snapshot of the machine as it was delivered.
Then log in as root (ssh root@adresse-du-vps) and install the latest security updates. On Debian or Ubuntu:
apt update && apt full-upgrade
On AlmaLinux or Rocky Linux: dnf upgrade. Reboot with reboot if a new kernel was installed (on Ubuntu, the file /var/run/reboot-required flags it). On a container VPS, the kernel is the host's: the provider updates it.
02
Creating a user for administration
Working as root all the time means giving full rights to the slightest typo and to anyone who steals that account. Create your own user (here alice) and give it sudo rights:
apt install sudo (already present on Ubuntu, sometimes missing from a minimal Debian);
adduser alice, then choose a strong password: it will be used for sudo and the console;
usermod -aG sudo alice (on AlmaLinux or Rocky Linux, the group is called wheel).
Open a second session with this account and check that sudo whoami returns root. Don't close the root session until it does.
03
Logging in with an SSH key
An SSH key can't be guessed, unlike a password. It has two parts: a private key, which never leaves your computer, and a public key, which you place on the server.
- On your computer (Linux, macOS, or Windows 10 and 11 in PowerShell):
ssh-keygen -t ed25519. Accept the suggested location and choose a passphrase: it protects the key if your computer is stolen.
- Copy the public key to the VPS:
ssh-copy-id alice@adresse-du-vps. On Windows, where ssh-copy-id doesn't exist, open the id_ed25519.pub file in the .ssh folder of your profile, and paste its contents, on a single line, into the ~/.ssh/authorized_keys file of the alice account on the server.
- On the server, logged in as
alice, check the permissions: chmod 700 ~/.ssh then chmod 600 ~/.ssh/authorized_keys. If the permissions are too broad, SSH ignores the key.
- Test:
ssh alice@adresse-du-vps should log you in without asking for the account password (only the key's passphrase, if you set one).
04
Shutting the door on passwords
Once key login is confirmed, disable passwords and direct root login. Rather than editing /etc/ssh/sshd_config, create a separate file: sudo nano /etc/ssh/sshd_config.d/00-durcissement.conf, with these three lines:
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
The name starts with 00 for a reason: SSH keeps the first value it reads, and some Ubuntu images already contain a 50-cloud-init.conf file that re-enables passwords.
- check the syntax with
sudo sshd -t (no output means no errors);
- apply with
sudo systemctl restart ssh (the service is called sshd on AlmaLinux and Rocky Linux);
- check the configuration actually in effect:
sudo sshd -T | grep -Ei 'passwordauth|permitroot'.
Keep your session open and test the connection in a new window: if something is wrong, you can fix it without locking yourself out.
05
Firewall: open only what's needed
A firewall only lets in what you have decided. On Debian or Ubuntu, ufw is the simplest. In this order, so you don't lose access:
sudo apt install ufw;
sudo ufw default deny incoming then sudo ufw default allow outgoing;
sudo ufw allow OpenSSH, before anything else;
sudo ufw allow 80,443/tcp for a website, or your application's port;
sudo ufw enable, then sudo ufw status verbose to review the rules.
If your IP address is fixed, you can restrict SSH to it alone: sudo ufw allow from 203.0.113.10 to any port 22 proto tcp, then sudo ufw delete allow OpenSSH. Replace the example address with your own.
To see what is actually listening on the machine, run sudo ss -tulpn. A database (MariaDB, PostgreSQL, Redis) almost never needs to be open to the world: it should listen on 127.0.0.1, or be open only to your services' addresses.
A well-known trap: ports published by Docker bypass ufw rules. Publish them on 127.0.0.1 (-p 127.0.0.1:8080:80) with a proxy in front, or filter them in the DOCKER-USER chain.
06
Automatic updates and fail2ban
Vulnerabilities get fixed quickly, but you still have to install the fixes. On Debian and Ubuntu:
sudo apt install unattended-upgrades;
sudo dpkg-reconfigure --priority=low unattended-upgrades, and answer ‘Yes’.
By default, only security fixes install automatically; major updates are left to you. The log is in /var/log/unattended-upgrades/.
fail2ban reads the logs and temporarily bans addresses that rack up failed login attempts. With key login, passwords are already refused: fail2ban mainly cuts down the noise from bots. Install it with sudo apt install fail2ban python3-systemd, then create /etc/fail2ban/jail.local:
[sshd]
enabled = true
backend = systemd
The line backend = systemd avoids a Debian 12 trap: it no longer writes a /var/log/auth.log file by default, and without this line fail2ban may refuse to start. Restart with sudo systemctl restart fail2ban and check with sudo fail2ban-client status sshd.
07
Backing up and monitoring
No setting replaces a backup. Plan for two levels:
- a snapshot, from the customer area, before any risky change (major update, network or firewall change): if something breaks, you're back to the previous state in a few minutes;
- an automatic off-machine copy of your important data: site files, database exports (
mysqldump, pg_dump), configuration. Tools such as restic or borg encrypt these copies and send them to another server or remote storage.
A backup that has never been restored is just a hope: test a restore from time to time.
For monitoring, a few commands are enough to start with: journalctl -u ssh (SSH logins), sudo ufw status (firewall), df -h (disk space), systemctl --failed (failed services). A full disk is one of the most common failures: keep an eye on it.
08
What CloudFive already does
Every CloudFive VPS sits behind our anti-DDoS, which filters out denial-of-service attacks before they reach the machine. The customer area console gives you back control when SSH or the network stops responding, snapshots and reinstallation are launched from the customer area, and the reverse DNS of your dedicated IPv4 address can be changed there too.
These protections don't replace the settings above: on a VPS, the security of the system, accounts and applications stays in your hands. If you'd rather not manage anything, web hosting or a game server plan takes care of this work for you.
For Docker or a VPN such as WireGuard, choose the KVM VPS, which has its own kernel; for other uses, the Ryzen VPS or the Intel VPS.
09
Frequently asked questions
Should I change the SSH port?
It is not a protection in itself, but it reduces bot noise in the logs. The real protection is key-based login and disabling passwords.
What if I can no longer connect over SSH?
Open the console from the VPS page in the customer area: it works even when the network or SSH no longer respond, and lets you fix the configuration.
I've lost my SSH key, what should I do?
Open the console from the customer area, log in with your user's password, then add a new public key to the ~/.ssh/authorized_keys file. Remove the old key if the computer was lost or stolen.
Is fail2ban enough to protect the server?
No. fail2ban reduces bot noise, but the real protection is key login, disabled passwords, a firewall that only lets through what's needed, and regular updates.
Do you need antivirus on a Linux VPS?
It isn't the priority. Break-ins on a Linux server mostly come through a weak password, out-of-date software or a service exposed by mistake. An antivirus such as ClamAV can help if the server receives users' files, for example email attachments.