nordelo
Menu

Guides

Secure your new Linux VPS in ten minutes

Update the system, add your own user, log in with an SSH key, turn off passwords and switch on a firewall. For Ubuntu and Debian.

A new server on the internet gets login attempts within minutes. These steps close the most common doors. The commands are for Ubuntu 24.04 and Debian 12 and 13. Run them as root after you have connected with SSH.

1. Update the system

apt update && apt upgrade -y && apt install -y sudo

2. Add your own user

Replace ara with your name. You choose a password, which you then use for sudo.

adduser ara
usermod -aG sudo ara

3. Log in with an SSH key

Run this on your own computer, not on the server. Press Enter at the prompts, or choose a passphrase for extra protection.

ssh-keygen -t ed25519
ssh-copy-id ara@203.0.113.10

Windows has no ssh-copy-id. Run this in PowerShell instead:

type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh ara@203.0.113.10 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Check that ssh ara@203.0.113.10 logs in without asking for the server password before you go on.

4. Turn off passwords and root login

Only do this once step 3 works, or you lock yourself out.

sudo tee /etc/ssh/sshd_config.d/10-nordelo.conf <<EOF
PasswordAuthentication no
PermitRootLogin no
EOF
sudo systemctl restart ssh

Keep your current window open and test logging in from a new one. If that works, you can close the old one.

5. Switch on the firewall

Let in only what you use. SSH first, or you lock yourself out.

sudo apt install -y ufw
sudo ufw allow OpenSSH
sudo ufw enable

If you run a website, open web traffic too with sudo ufw allow 80,443/tcp.

6. Automatic security updates

sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades

Answer Yes. Security updates now install every day without you doing anything.

Running AlmaLinux or Rocky Linux?

The steps are the same, but packages install with dnf, the group is wheel instead of sudo, the SSH service is sshd and the firewall is firewalld.

See the VPS sizes