A new VPS gets an IPv4 address that someone else may have used yesterday, and within minutes of it going online, automated scanners begin knocking on its SSH port with lists of common user names and passwords. Most break-ins on small servers are not clever: a weak password, a forgotten service listening to the world, or a known flaw left unpatched for months. The good news is that ten steps, most of them a few commands each, close nearly all of these doors. This guide follows the order we recommend for the first hour of a new server, with commands for Ubuntu 24.04 and Debian 12 and for AlmaLinux 9. The examples use a clinic in Kuwait City that just moved its appointment system to a VPS.
011. Update now, and keep updating on its own
The template your server was installed from was built weeks or months ago, and security fixes have come out since. Install them before anything else, and reboot if the kernel was updated:
# Ubuntu and Debiansudo apt update && sudo apt full-upgrade# Is a reboot needed?ls /var/run/reboot-required# AlmaLinuxsudo dnf upgrade --refresh# Prints whether a reboot is neededsudo dnf install dnf-utils && sudo needs-restarting -r
Then let the server install security updates by itself. On Ubuntu, is installed and on by default and applies security updates once a day; on Debian you install and enable it. On AlmaLinux the equivalent is dnf-automatic:
# Ubuntu and Debian: install it, then answer Yessudo apt install unattended-upgradessudo dpkg-reconfigure -plow unattended-upgrades# AlmaLinux: in /etc/dnf/automatic.conf set# upgrade_type = security# apply_updates = yessudo dnf install dnf-automaticsudo systemctl enable --now dnf-automatic.timer
Automatic updates do not reboot by default. That is a sensible choice for a production server, but it means kernel fixes wait for you, which step 10 deals with.
022. Work as a normal user with sudo
Root can do anything without asking, including deleting the whole system with one typo. Create a user of your own and give it sudo, so dangerous commands need a deliberate word in front of them and every use is logged:
# Ubuntu and Debiansudo adduser clinicadminsudo usermod -aG sudo clinicadmin# AlmaLinuxsudo useradd -m clinicadminsudo passwd clinicadminsudo usermod -aG wheel clinicadmin# Check it works before you go furthersu - clinicadminsudo whoami
The last command should print root. Give each person who manages the server their own user, never a shared one, so the logs say who did what and you can remove one person’s access without changing everyone’s.
033. Log in with SSH keys and turn off passwords
A password can be guessed, however long the list of attempts has to be. An cannot be guessed in practice: the private half stays on your computer, and the server only holds the public half. Create a key on your own computer, not on the server, and copy it across:
# On your computer (Windows 10 and 11 include ssh in PowerShell)ssh-keygen -t ed25519 -C "clinic laptop"ssh-copy-id clinicadmin@SERVER_IP# On Windows, which has no ssh-copy-id, paste the .pub file’s line into# ~/.ssh/authorized_keys on the server instead# Then test it: this should log in without asking for the server passwordssh clinicadmin@SERVER_IP
Protect the key with a passphrase when ssh-keygen asks; if the laptop is stolen, the key alone is not enough. Once logging in with the key works, turn off passwords and direct root logins. Put the settings in a file of their own, so a system update never overwrites them:
# /etc/ssh/sshd_config.d/00-hardening.confPasswordAuthentication noKbdInteractiveAuthentication noPermitRootLogin noMaxAuthTries 3# Check the syntax, then restart SSH (ssh on Ubuntu and Debian, sshd on AlmaLinux)sudo sshd -tsudo systemctl restart ssh# Confirm what SSH actually usessudo sshd -T | grep -E "passwordauthentication|permitrootlogin"
The file name starts with 00 on purpose. SSH reads the files in sshd_config.d in alphabetical order and keeps the first value it meets, and many cloud images ship a file such as 50-cloud-init.conf that turns passwords back on. Before you close your current session, open a second window and log in again: if something is wrong, the first window is still there to fix it. We covered key logins in more depth in our guide to SSH logins without a password.
044. Turn on a firewall
A firewall decides which ports the world may reach. The rule is simple: deny everything coming in, then allow only what the server exists to serve. Allow SSH first, or you will lock yourself out:
# Ubuntu and Debian (Debian: sudo apt install ufw first)sudo ufw default deny incomingsudo ufw default allow outgoingsudo ufw allow OpenSSHsudo ufw allow 80,443/tcpsudo ufw enablesudo ufw status verbose# AlmaLinux (firewalld)sudo systemctl enable --now firewalldsudo firewall-cmd --permanent --add-service=sshsudo firewall-cmd --permanent --add-service=http --add-service=httpssudo firewall-cmd --reloadsudo firewall-cmd --list-all
For a service only you should reach, such as a database admin page, allow your own address alone: sudo ufw allow from YOUR_IP to any port 8443 proto tcp. And if you run Docker, remember that ports published by containers bypass ufw, so bind private ones to 127.0.0.1.
055. Ban repeated failures with fail2ban
With passwords off, guessing cannot succeed, but the attempts still fill your logs and use resources. reads the logs and blocks, for a while, any address that fails too often. Create a jail.local file rather than editing jail.conf, which updates replace:
# Ubuntu and Debiansudo apt install fail2ban python3-systemd# AlmaLinux (from EPEL)sudo dnf install epel-releasesudo dnf install fail2ban fail2ban-firewalld# /etc/fail2ban/jail.local[DEFAULT]bantime = 1hfindtime = 10mmaxretry = 5ignoreip = 127.0.0.1/8 ::1 YOUR_IP[sshd]enabled = truebackend = systemd# Thensudo systemctl enable --now fail2bansudo fail2ban-client status sshd
The line backend = systemd makes fail2ban read the systemd journal, which works on all three systems; Debian 12 keeps no /var/log/auth.log by default, and an sshd jail that looks for that file will not start. Put your own fixed address in ignoreip, if you have one, so a mistyped key never bans you. The same tool protects WordPress logins, mail and other services with their own jails.
066. Close the services you do not need
Every service listening on a public address is a door. List what listens, and ask of each one: does the internet need this?
# Every listening port, and which program owns itsudo ss -tulpn# Every running servicesystemctl list-units --type=service --state=running# Stop and disable one you do not need, for examplesudo systemctl disable --now cups
Look hard at lines with 0.0.0.0 or [::] in them, which mean all addresses. A database such as MySQL, MariaDB, PostgreSQL or Redis on the same server as the application should listen on 127.0.0.1 only. If you need to reach it from your computer, use an SSH tunnel such as ssh -L 3306:127.0.0.1:3306 clinicadmin@SERVER_IP, rather than opening its port. And remove software you installed to try and no longer use: what is not installed cannot be attacked.
077. Set the time and learn to read the logs
Logs are only useful if their times are right. Certificates, two-factor codes and log correlation between servers all depend on an accurate clock, so make sure it is synchronised:
# Is the clock synchronised, and which time zone?timedatectlsudo timedatectl set-timezone Asia/Dubai# AlmaLinux uses chrony; check its sourceschronyc sources# Recent SSH logins and failures (sshd on AlmaLinux)sudo journalctl -u ssh --since "today"# Who logged in, and from wherelast -a | head
Many administrators leave servers on UTC and convert in their heads, which makes comparing logs across countries easier; either is fine if you are consistent. The systemd journal holds most of what you need. Make sure it survives reboots by setting Storage=persistent in /etc/systemd/journald.conf, and cap its size with SystemMaxUse=500M so it never fills the disk. Read it for five minutes every week at first; you learn what normal looks like, and abnormal stands out.
088. Back up off the server, and test the restore
Every step so far lowers the chance of trouble; backups are what you have when it comes anyway, whether from an attack, a mistaken rm or a bad update. The rule of thumb is : three copies of your data, on two different kinds of storage, one of them away from the server. A copy on the same disk does not count, and neither does one an attacker who owns the server can delete.
- What to copy: Databases as dumps, the application’s files and uploads, the configuration under /etc, and the list of what you installed. The operating system itself can be reinstalled.
- How often: As often as the data you can afford to lose: daily for most sites, more often for a busy shop or an appointment system.
- Where: On separate storage, encrypted, with a tool such as restic or BorgBackup that keeps versions, so a file encrypted by ransomware today does not overwrite yesterday’s good copy.
- Test the restore: Restore to a test server every few months, and time it. That number is how long you will be down on a bad day.
# A daily MariaDB dump, kept for 14 dayssudo mariadb-dump --single-transaction --all-databases | gzip > /var/backups/db-$(date +%F).sql.gzsudo find /var/backups -name "db-*.sql.gz" -mtime +14 -delete# restic: encrypted, versioned copies to separate storagerestic -r sftp:backup@BACKUP_HOST:/srv/restic/clinic initrestic -r sftp:backup@BACKUP_HOST:/srv/restic/clinic backup /etc /var/www /var/backups
099. Monitor the server from somewhere else
You want to hear that the site is down, the disk is 90% full or the load has been high for an hour from an alert, not from a customer. Two kinds of monitoring cover most needs: an uptime check that visits your site every minute or so and alerts you when it fails, and resource metrics that track CPU, memory and disk over time. Uptime Kuma does the first and Prometheus with Grafana does the second, and both run happily in Docker.
Run the monitor on a different server from the one it watches: a server cannot send an alert when it is itself down. Watch the security signals too: a sudden jump in failed logins, a new user in /etc/passwd, or a process using all the CPU at night, which is often a cryptocurrency miner left by an intruder.
1010. Patch the kernel on time
Most updates take effect when the service restarts, but a kernel update only takes effect after a reboot. Until then the server runs the old, vulnerable kernel, even though the new one is installed. So plan a regular reboot window, weekly or monthly at a quiet hour, and reboot sooner when a serious kernel flaw is announced. The commands in step 1 tell you whether a reboot is pending.
If you cannot reboot often, applies kernel security fixes to the running kernel in memory, with no reboot. KernelCare from TuxCare is one such service and supports Ubuntu, Debian, AlmaLinux and other distributions; it checks for new patches every four hours. Canonical’s Livepatch does the same on Ubuntu through Ubuntu Pro.
# KernelCare: install, then register a key-based licencecurl -s -L https://kernelcare.com/installer | sudo bashsudo kcarectl --register KEY# Applied patches, and the effective kernel versionsudo kcarectl --infosudo kcarectl --uname
Live patching closes the urgent gap, but it is not a reason never to reboot: reboot to the new kernel at your next planned window anyway.
11Keep keys and passwords in a password manager
The ten steps protect the server; the weak point that remains is often the people around it. A password reused from a leaked site, a root password in a shared spreadsheet, a database password in a chat message. A password manager gives every account a long random password and lets the team share only what each person needs.
Vaultwarden is a lightweight, open-source server compatible with the official Bitwarden apps and browser extensions, under the AGPL-3.0 licence. It is not associated with Bitwarden, Inc. It runs comfortably on a small VPS, and a few rules keep it safe:
- HTTPS only: The web vault requires HTTPS, because the browser’s cryptography works only in a secure context. Put it behind a reverse proxy with a valid certificate.
- Close registration: After creating the accounts your team needs, set SIGNUPS_ALLOWED=false so strangers cannot sign up, and invite new members from the admin page.
- Back it up: Its data folder holds every password your team has. Copy it off the server like your most important database, encrypted.
- Two-factor for everyone: Turn on two-factor authentication for every account, starting with yours.
- ProblemPermission denied (publickey) after turning off passwords
- FixThe key is not in ~/.ssh/authorized_keys of the right user, or the folder permissions are too open. From your still-open session run chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys. If no session is open, use the server console in the control panel.
- ProblemPasswordAuthentication no has no effect
- FixAnother file in /etc/ssh/sshd_config.d sets it to yes first. sudo sshd -T shows the value in use; name your file so it sorts first.
- Problemfail2ban will not start on Debian 12
- FixThe sshd jail looks for /var/log/auth.log, which Debian 12 does not create. Add backend = systemd to the [sshd] section.
- ProblemYou locked yourself out with the firewall
- FixLog in through the control panel’s console, allow SSH, then enable the firewall again. Always allow SSH before ufw enable.
- ProblemThe disk fills up with logs
- FixCap the journal with SystemMaxUse in journald.conf, check logrotate for application logs, and run sudo journalctl --vacuum-size=500M to free space now.
12Securing a CoreVPS server
Every CoreVPS plan gives you full root access, so all ten steps above apply as written. You choose the system on the order form, from 32 templates in 9 systems, with Ubuntu 24.04 as the default, and the commands in this guide cover Ubuntu, Debian and AlmaLinux. A few things on CoreVPS shorten the list:
- Imunify360 and KernelCare on CoreVPS with CloudLinux OS: The CoreVPS with CloudLinux OS plans arrive with CloudLinux OS and Imunify360 installed and switched on, their licences included in the price, and KernelCare comes with Imunify360. The plans are CoreVPS One at $12, Team at $19.50, Studio at $31, Agency at $43 and Enterprise at $65 a month, on the Solo, Admin or Shared Pro editions of the licence.
- KernelCare with a control panel licence: If you add a cPanel or Plesk licence in the CoreVPS builder, KernelCare is a $3 monthly add-on beside it.
- Vaultwarden as a ready app: Pick it under «Preinstalled software» on the order form, after choosing the system. It runs from the VPS Start plan, with 1 vCPU, 1 GB of memory and 20 GB of NVMe, and the email you receive after delivery holds its address and setup steps.
- Monitoring as ready apps: Uptime Kuma and Grafana also run from VPS Start, so a second small server can watch your main one. Wazuh, for security monitoring across several servers, starts from VPS Max.
CoreVPS has nearly 100 ready apps in all, and the order form shows only those that support the chosen system and fit the plan. The current plans are in our Germany data centre. If you are unsure which step matters most for your server, ask our technical support team.




