Freshly delivered, your Linux VPS is clean. These commands make it ready and safe in five minutes. Log in over SSH as root (how to connect) and go in order.
1. Update everything
apt update && apt upgrade -y
If the file /var/run/reboot-required exists afterwards, restart with reboot (the kernel was updated).
2. Your time zone
timedatectl set-timezone Europe/London
Others: Europe/Madrid, America/New_York, America/Sao_Paulo... Check it with timedatectl. It matters so logs, cron jobs and scheduled restarts follow your clock.
3. Basic tools
apt install -y htop curl wget unzip nano screen ufw
4. Firewall, without locking yourself out
First allow SSH, then enable the firewall. The other way round locks you out instantly:
ufw allow OpenSSH
ufw enable
ufw status
From then on, open only the ports you use: how to open ports on Linux. If you lock yourself out, use the VNC console and run ufw disable.
5. Automatic security updates
apt install -y unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades
Answer Yes. From then on, security patches install themselves every day, with no surprise reboots.
6. A regular user for daily work (recommended)
adduser yourname
usermod -aG sudo yourname
Log in as that user and put sudo in front of admin commands. It makes it harder to break something by accident.
If you use Rocky Linux
Two things change: the package manager is dnf (dnf update -y) and the firewall is firewalld (firewall-cmd --permanent --add-service=ssh && firewall-cmd --reload).
Recommended next step: log in over SSH with a key instead of a password.