A freshly installed server is exposed to the internet from the minute it gets a public IP address. Automated scanners start probing SSH and common ports within minutes, looking for weak passwords and unpatched software. None of that is a reason to panic, but it is a reason to spend the first half hour on a few basic steps before you install your application. This checklist covers the ten steps we recommend on every new VPS or dedicated server. Commands are shown for Ubuntu and Debian, with AlmaLinux equivalents where they differ.
One rule before you start: keep your current SSH session open while you change SSH or firewall settings, and test every change from a second terminal. If something goes wrong, the open session is your way back in.
1. Update the system
Install images are often weeks or months old, so the first job is to pull in every security fix released since then.
# Ubuntu / Debian
apt update && apt full-upgrade -y
# AlmaLinux
dnf upgrade -y
If the kernel was updated, reboot now, while nothing important is running yet.
2. Create a regular user with sudo rights
Working as root all the time means every typo runs with full privileges. Create a personal account and give it administrative rights through sudo:
# Ubuntu / Debian
adduser alex
usermod -aG sudo alex
# AlmaLinux
useradd -m alex
passwd alex
usermod -aG wheel alex
Use one account per person. Shared logins make it impossible to tell who changed what, and painful to remove access when someone leaves.
3. Switch to SSH key authentication
SSH keys are far harder to brute-force than passwords. On your own computer, create a key pair (if you do not already have one) and copy the public key to the server:
ssh-keygen -t ed25519 -C "alex@laptop"
ssh-copy-id alex@203.0.113.10
Protect the private key with a passphrase. Then open a new terminal and confirm you can log in as the new user with the key, and that sudo -v works, before moving on.
4. Disable root login and password logins over SSH
Once key login works for your regular user, turn off the two things attackers try most: logging in as root and guessing passwords. On current Ubuntu, Debian and AlmaLinux releases the main sshd_config includes files from /etc/ssh/sshd_config.d/, and for each setting the first value sshd reads wins. Cloud images sometimes ship a file such as 50-cloud-init.conf that turns password authentication back on, so give your file a name that sorts first:
# /etc/ssh/sshd_config.d/00-hardening.conf
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
Check the syntax and the effective values, then restart SSH:
sudo sshd -t
sudo sshd -T | grep -Ei 'permitrootlogin|passwordauthentication'
# Ubuntu / Debian
sudo systemctl restart ssh
# AlmaLinux
sudo systemctl restart sshd
If Ubuntu reports a missing privilege separation directory, run sudo mkdir -p /run/sshd and repeat the check. Test a new login from a second terminal before you close the old one. Moving SSH to a non-standard port reduces log noise but is not real protection; keys and the steps below matter much more.
5. Turn on a firewall
Allow only the ports you actually need. On Ubuntu and Debian, UFW is the simplest option (on Debian install it first with apt install ufw):
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 80,443/tcp # only if this is a web server
sudo ufw enable
sudo ufw status verbose
AlmaLinux uses firewalld, which is normally active out of the box:
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --reload
Note for Docker users: ports published with docker run -p are handled by Docker’s own firewall rules and can bypass UFW. Bind containers to 127.0.0.1 unless they really need to be public.
6. Enable automatic security updates
Most compromises use vulnerabilities that already have a patch. Let the server install security updates by itself:
# Ubuntu (usually preinstalled) / Debian
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
# AlmaLinux
sudo dnf install dnf-automatic
# in /etc/dnf/automatic.conf set:
# upgrade_type = security
# apply_updates = yes
sudo systemctl enable --now dnf-automatic.timer
Automatic updates do not reboot into a new kernel by default. Check regularly whether a reboot is pending: on Ubuntu the file /var/run/reboot-required appears, and on AlmaLinux dnf needs-restarting -r tells you.
7. Install Fail2ban
Even with passwords disabled, bots keep knocking. Fail2ban watches the logs and temporarily blocks IP addresses that fail to log in repeatedly, which cuts noise and protects other services you add later.
# Ubuntu / Debian
sudo apt install fail2ban python3-systemd
# AlmaLinux (Fail2ban comes from EPEL)
sudo dnf install epel-release
sudo dnf install fail2ban
Never edit jail.conf directly; create /etc/fail2ban/jail.local instead. Reading the systemd journal works on all three systems, including Debian 12 and newer, which no longer write /var/log/auth.log by default:
[sshd]
enabled = true
backend = systemd
maxretry = 5
bantime = 1h
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd
8. Remove what you do not need
Every running service is something that can be attacked. List what is listening on the network:
sudo ss -tulpn
Anything you do not recognise or do not need should be stopped and disabled (sudo systemctl disable --now <service>) or uninstalled. Databases such as MySQL, PostgreSQL or Redis should normally listen only on 127.0.0.1, not on the public interface.
9. Set up off-server backups
Security is also about recovery. Disks fail, people delete the wrong folder, and ransomware exists. A backup that lives on the same server is lost together with it, so copy your data and database dumps to a different machine or storage service, keep several versions, and test a restore at least once. Treat backup credentials carefully: if the server can delete its own backups, so can an attacker who takes over the server.
10. Monitor and review
Finally, make sure you notice problems before your customers do:
- Set up an external uptime check for your site or service, with alerts by e-mail or chat.
- Keep an eye on disk space (
df -h) and memory (free -h); full disks cause many outages. - Review SSH logins now and then with
journalctl -u ssh(-u sshdon AlmaLinux) andlast. - Remove SSH keys and accounts of people who no longer need access.
Quick reference
| Step | Ubuntu / Debian | AlmaLinux |
|---|---|---|
| Updates | apt full-upgrade |
dnf upgrade |
| Admin group | sudo |
wheel |
| SSH service | ssh |
sshd |
| Firewall | UFW | firewalld |
| Auto updates | unattended-upgrades | dnf-automatic |
| Fail2ban | main repository | EPEL |
Unmanaged or managed?
All servers at Astra Hosting come unmanaged with full root access, so you decide how every one of these steps is done. If you would rather not do it yourself, our Managed service covers initial setup, OS and security updates, firewall and brute-force protection, monitoring and daily off-server backups for +€50/month on a VPS or +€200/month on a dedicated server. Our guide to managed vs unmanaged servers explains the trade-offs in more detail.
Ready to put this checklist to work? Pick a Cloud or Performance VPS from €4.59/month or a dedicated server in one of 13 countries, and follow the steps above on day one. If you have questions about securing your setup, write to us at support@astrahosting.com.