A freshly installed server is reachable from the entire internet within seconds of booting, and automated scanners will start trying passwords on port 22 almost immediately. Spending fifteen minutes on the steps below before you install anything else removes most of the common risks.
The commands are for Ubuntu 22.04 / 24.04 and Debian 11 / 12. Where AlmaLinux, Rocky Linux or CentOS differ, the alternative is shown.
1. Log in and update everything
Your login details (IP, root password) are in the welcome email and in the client area under My Services.
ssh root@YOUR_SERVER_IP
Update the package lists and install all pending updates:
# Ubuntu / Debian
apt update && apt -y full-upgrade
# AlmaLinux / Rocky / CentOS
dnf -y upgrade # or: yum -y update on CentOS 7
If the kernel was updated, reboot once with reboot and log back in.
2. Change the root password
Even if you will disable password logins later, replace the password from the welcome email:
passwd
Use a long random password and store it in a password manager.
3. Create a normal user with sudo
Working as root all the time makes mistakes more expensive. Create your own user:
# Ubuntu / Debian
adduser deploy
usermod -aG sudo deploy
# AlmaLinux / Rocky / CentOS
adduser deploy
passwd deploy
usermod -aG wheel deploy
Open a second terminal and confirm you can log in as the new user and run sudo whoami (it should print root) before you continue.
4. Switch to SSH key authentication
On your own computer (not the server), create a key if you do not already have one:
ssh-keygen -t ed25519 -C "you@laptop"
Copy the public key to the server:
ssh-copy-id deploy@YOUR_SERVER_IP
On Windows without ssh-copy-id, paste the contents of C:\Users\YOU\.ssh\id_ed25519.pub into /home/deploy/.ssh/authorized_keys on the server, then run chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys.
Test that ssh deploy@YOUR_SERVER_IP logs you in without asking for a password.
5. Harden the SSH daemon
Now turn off password logins and direct root logins. Create a drop-in file so package upgrades do not overwrite your settings:
sudo tee /etc/ssh/sshd_config.d/99-hardening.conf >/dev/null <<'EOF'
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
EOF
Check the syntax and reload:
sudo sshd -t && sudo systemctl reload ssh # Debian / Ubuntu
sudo sshd -t && sudo systemctl reload sshd # AlmaLinux / CentOS
Keep your current session open and test a fresh login in another window. If something goes wrong, you can still fix it — and if you lock yourself out completely, the VNC console in the server control panel gives you keyboard access without SSH.
Changing the SSH port (for example to 2222) is optional. It does not add real security, but it does cut log noise from bots. If you change it, open the new port in your firewall first.
6. Set the hostname and time zone
sudo hostnamectl set-hostname web01
sudo timedatectl set-timezone Asia/Hong_Kong # or UTC
timedatectl
Make sure “System clock synchronized: yes” is shown. Accurate time matters for TLS certificates, logs and two-factor authentication.
7. Enable a firewall
Allow only the ports you need. On Ubuntu and Debian, UFW is the simplest option — see our UFW firewall guide. The short version:
sudo apt install -y ufw
sudo ufw allow OpenSSH
sudo ufw enable
On AlmaLinux and Rocky Linux, firewalld is already installed: sudo firewall-cmd --permanent --add-service=ssh && sudo firewall-cmd --reload.
8. Install Fail2ban
Fail2ban watches the logs and temporarily bans IPs that keep failing to log in:
sudo apt install -y fail2ban # Ubuntu / Debian
sudo dnf install -y epel-release fail2ban && sudo systemctl enable --now fail2ban # Alma / Rocky
The default configuration already protects SSH. Check it with sudo fail2ban-client status sshd.
9. Turn on automatic security updates
# Ubuntu / Debian
sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
# AlmaLinux / Rocky
sudo dnf install -y dnf-automatic
sudo systemctl enable --now dnf-automatic-install.timer
10. Plan your backups
Hardware fails, and so do people — a wrong rm -rf is just as final as a dead disk. Keep your own backups rather than relying on anyone else’s. Decide now where copies of your data will live — another server, object storage or your own machine — and test a restore before you need one.
Checklist
- System fully updated and rebooted
- Root password changed
- Sudo user created and tested
- SSH keys working, passwords and root login disabled
- Hostname and time zone set
- Firewall enabled with only required ports open
- Fail2ban running
- Automatic security updates enabled
- Backup plan in place
With that done, continue with Nginx and a free HTTPS certificate or install a panel such as aaPanel or 1Panel.