Once you have root access to a server, keeping it secure is your job. Doing these four basics on day one blocks most automated attacks: SSH keys, no password logins, a firewall and regular updates.
Before you start
- You need SSH access as root. Your IP address and password are in your activation email or in the service details under Client area > My services.
- Commands are given separately for Ubuntu/Debian and AlmaLinux/Rocky Linux.
- Keep your current SSH session open while you change settings, and test each change from a second terminal window.
1. Update the system
Start by patching known vulnerabilities in the installed packages.
# Ubuntu / Debian
apt update && apt upgrade -y
# AlmaLinux / Rocky Linux
dnf upgrade -y
To have security updates installed automatically:
# Ubuntu / Debian
apt install -y unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades
# AlmaLinux / Rocky Linux
dnf install -y dnf-automatic
systemctl enable --now dnf-automatic-install.timer
2. Create an SSH key and add it to the server
- Generate a key pair on your computer. In Windows PowerShell or a macOS/Linux terminal:
When prompted, we recommend setting a passphrase to protect the key.ssh-keygen -t ed25519 -C "user@example.com" - Copy the public key to the server. On macOS and Linux:
Windows has nossh-copy-id root@203.0.113.10ssh-copy-id, so use this instead:type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh root@203.0.113.10 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys" - Check that key login works. Open a new terminal and run
ssh root@203.0.113.10. You should get in without the server password (at most, you will be asked for your key passphrase).
3. Turn off password login
Once key login works, edit /etc/ssh/sshd_config (for example with nano /etc/ssh/sshd_config) and set:
PermitRootLogin prohibit-password
PasswordAuthentication no
On recent Ubuntu releases, files in /etc/ssh/sshd_config.d/ can override these settings. If one of them contains PasswordAuthentication yes, change that too. Then test the configuration and restart the service:
sshd -t
# Ubuntu / Debian
systemctl restart ssh
# AlmaLinux / Rocky Linux
systemctl restart sshd
After the restart, keep your open session and try connecting with your key from a second window. If it fails, undo the change from the session that is still open.
4. Enable a firewall
Only allow the ports your services actually use. Add the SSH (22) rule before you switch the firewall on.
# Ubuntu / Debian (ufw)
apt install -y ufw
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
ufw status
# AlmaLinux / Rocky Linux (firewalld)
dnf install -y firewalld
systemctl enable --now firewalld
firewall-cmd --permanent --add-service=ssh
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
If you don't run a web server, skip the 80 and 443 lines.
5. Stop brute-force attempts with fail2ban
fail2ban temporarily blocks IP addresses after repeated failed logins.
# Ubuntu / Debian
apt install -y fail2ban
# AlmaLinux / Rocky Linux (needs the EPEL repository)
dnf install -y epel-release && dnf install -y fail2ban
systemctl enable --now fail2ban
fail2ban-client status sshd
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The server still asks for a password even with a key | Wrong permissions on authorized_keys | Run chmod 700 ~/.ssh and chmod 600 ~/.ssh/authorized_keys. |
| I can't connect after enabling the firewall | The firewall went on before the SSH rule was added | If you have no console access in the panel, open a support ticket. |
| My own IP got blocked | fail2ban banned it after a few failed attempts | Connect from another network and run fail2ban-client set sshd unbanip IP. |
Frequently asked questions
Should I change the SSH port?
A different port cuts down log noise from bots, but it is not real protection. Key-only login and fail2ban are what keep you safe. If you do change the port, allow the new one in your firewall first.
Should I use a separate user instead of root?
Yes, it is good practice. Create a user with adduser, add it to the sudo group (Ubuntu/Debian) or wheel group (AlmaLinux/Rocky), then disable root login entirely with PermitRootLogin no.
Does this make my server fully secure?
It gives you a solid baseline. Keeping your applications up to date, taking regular backups and watching your logs are also part of security.
Stuck somewhere? Open a ticket from the client area or contact us. For servers with full root access, see VDS servers.