Your new VPS is online, you have the IP address and root password, and you're ready to build. But a fresh server is reachable from the whole internet from the moment it boots, and automated bots start trying to log in almost immediately.
Spend half an hour on these ten steps first. The examples use Ubuntu or Debian commands, with notes for AlmaLinux, Rocky Linux and CentOS where they differ.
1. Log in over SSH
Your welcome email includes your server's IP address, username (usually root) and password. From Terminal (Mac or Linux) or PowerShell (Windows 10/11):
ssh root@YOUR_SERVER_IP
Type yes to accept the fingerprint the first time, then paste your password. Nothing appears as you type it. That's normal. Full instructions, including PuTTY on Windows: your first SSH login.
2. Update everything
Install the latest security patches before anything else.
Ubuntu or Debian:
apt update && apt upgrade -y
AlmaLinux, Rocky or CentOS:
dnf update -y
Reboot if the kernel was updated: reboot.
3. Change the root password
Set a new, long, unique root password, even if you plan to disable password logins later:
passwd
4. Create a regular user with sudo
Working as root all the time is risky. Create your own user and give it admin rights.
Ubuntu or Debian:
adduser yourname
usermod -aG sudo yourname
AlmaLinux, Rocky or CentOS:
adduser yourname
passwd yourname
usermod -aG wheel yourname
5. Set up SSH keys
SSH keys are far more secure than passwords. On your own computer (not the server), create a key if you don't have one:
ssh-keygen -t ed25519
Then copy it to the server for your new user:
ssh-copy-id yourname@YOUR_SERVER_IP
(On Windows without ssh-copy-id, paste the contents of your .pub file into /home/yourname/.ssh/authorized_keys on the server.)
Test it in a new terminal window: ssh yourname@YOUR_SERVER_IP. Keep your original session open until you're sure it works.
6. Disable root login and password authentication
Once key login works for your user, edit the SSH configuration:
sudo nano /etc/ssh/sshd_config
Set:
PermitRootLogin no
PasswordAuthentication no
Some distributions also include files in /etc/ssh/sshd_config.d/ that override these settings, so check there too. Then restart SSH:
sudo systemctl restart ssh
(The service is called sshd on AlmaLinux, Rocky and CentOS.)
Test a new login before closing your current session. If something is wrong, you can still fix it.
7. Turn on a firewall
Allow only the ports you need. Always allow SSH first, or you'll lock yourself out.
Ubuntu or Debian (UFW):
sudo apt install ufw -y
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status verbose
AlmaLinux, Rocky or CentOS (firewalld):
sudo systemctl enable --now firewalld
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
Only open web ports if you're running a website. Keep database ports like 3306 closed to the internet.
8. Install fail2ban
fail2ban watches your logs and temporarily blocks IP addresses that keep failing to log in.
Ubuntu or Debian:
sudo apt install fail2ban -y
sudo systemctl enable --now fail2ban
On AlmaLinux and Rocky, fail2ban is available from the EPEL repository.
9. Turn on automatic security updates
Ubuntu or Debian:
sudo apt install unattended-upgrades -y
sudo dpkg-reconfigure --priority=low unattended-upgrades
AlmaLinux and Rocky: install dnf-automatic and enable its timer, configured to apply security updates.
10. Set the time zone, hostname and basic housekeeping
sudo timedatectl set-timezone America/Chicago
sudo hostnamectl set-hostname server1.yourdomain.com
Choose your own time zone and hostname. Correct time matters for logs, cron jobs and SSL.
Small servers can also benefit from a swap file, which gives the system some breathing room if memory runs low:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Bonus: plan backups and monitoring now
On an unmanaged server, backups are your responsibility. Before you put anything important on it:
- Set up automated, off-server backups. See the 3-2-1 backup rule.
- Add uptime monitoring and basic resource alerts.
- Keep a note of what you've installed and changed.
Know what your provider looks after
On an unmanaged server, you look after the operating system and software, and the provider looks after the hardware and network. If you lock yourself out, most providers offer a console or rescue mode, or can help you get back in.
Frequently asked questions
I locked myself out after changing SSH settings. What now?
Use your provider's console or rescue mode, or contact their support with your server's IP address. This is why it's important to test a new login before closing your current session.
Should I change the SSH port?
Changing it from 22 cuts down on automated login noise, but it isn't real security on its own. If you do change it, allow the new port in your firewall first, and include it when you connect.
Do I need a control panel on my VPS?
No. Many developers manage servers entirely from the command line. If you prefer a graphical panel, you can install one, though license costs may apply.
How often should I update?
Automatic security updates handle the urgent patches. Log in regularly to apply other updates and check that everything is running.
The bottom line
Update, change the root password, create a sudo user, switch to SSH keys, disable root and password logins, turn on a firewall and fail2ban, enable automatic security updates, and plan your backups. Then build.