A brand-new VPS is exposed to the internet from the moment it boots, and bots start probing SSH within minutes. These first steps on a new Linux VPS make it secure and ready for your apps. The commands target Ubuntu/Debian, with AlmaLinux/Rocky equivalents noted.
Before you start
- The VPS IP address and root password or SSH key from your provider.
- An SSH client (Terminal on macOS/Linux, Windows Terminal or PuTTY on Windows).
- Panel access (VNC console) in case you lock yourself out; see VNC console access.
Log in and update
ssh root@203.0.113.10apt update && apt upgrade -yOn AlmaLinux/Rocky: dnf upgrade -y. Reboot if the kernel was updated.
Set hostname and timezone
hostnamectl set-hostname vps1.example.comtimedatectl set-timezone Europe/BerlinCreate a sudo user
adduser deploy && usermod -aG sudo deployOn RHEL-family systems use the wheel group.
Set up SSH keys
On your own computer:
ssh-keygen -t ed25519ssh-copy-id deploy@203.0.113.10Log in as deploy in a new terminal to confirm it works before changing SSH settings.
Harden SSH
In /etc/ssh/sshd_config (or a file in sshd_config.d/) set:
PermitRootLogin no
PasswordAuthentication noThen sudo systemctl restart ssh (sshd on RHEL). More options in the SSH lockdown checklist.
Enable a firewall
sudo ufw allow OpenSSH && sudo ufw allow 80,443/tcp && sudo ufw enableOn AlmaLinux/Rocky use firewalld: firewall-cmd --permanent --add-service={ssh,http,https} && firewall-cmd --reload.
Automatic security updates
sudo apt install -y unattended-upgrades && sudo dpkg-reconfigure -plow unattended-upgradesRHEL family: dnf install dnf-automatic and enable its timer.
Add swap on small plans
A swap file prevents out-of-memory crashes on 1–2 GB VPSs. See create a swap file.
Plan backups and monitoring
- Enable provider backups if offered, and keep an off-site copy; see back up to S3 with rclone.
- Install fail2ban to block repeated login attempts.
- Watch resource usage with
htopand disk withdf -h.
Troubleshooting
- Locked out after SSH changes: use the VNC console to fix
sshd_config. - Firewall blocked SSH: from the console run
ufw allow OpenSSHorufw disable. - Permission denied (publickey): check
~/.ssh/authorized_keysownership and permissions (700 for the folder, 600 for the file).
Frequently asked questions
Should I change the SSH port?
It reduces log noise but is not real security. Keys and disabling passwords matter far more.
Which OS should I pick?
See Ubuntu vs Debian for a VPS.
Do I need a control panel?
Not necessarily. For hosting many websites without server admin, cPanel hosting may be easier.
