Task tutorial

Getting started with a Linux VPS

Harden a new Ubuntu VPS with updates, a non-root administrator, SSH keys, a firewall, automatic security updates, monitoring, and backups.

Format
Configure · Intermediate
Published
Published
Updated
Updated
Reading time
3 min read
Guide VPS Configure Intermediate Ubuntu Server vps

Key takeaways

  • Keep the original session open until a separate non-root, key-based login succeeds.
  • Validate SSH configuration and allow the active SSH port before enabling the firewall.
  • A secure baseline also needs updates, monitoring, backups, and tested recovery.

Before you begin

  • A newly provisioned Ubuntu VPS and provider console access
  • An SSH key pair on your local computer

The first hour with a new VPS sets the tone for its whole life — a few careful steps now spare you the 2 a.m. variety later. These steps target a current Ubuntu Server installation; other distributions use different package, firewall, and service commands. Whatever you do, keep the provider’s console access handy so a firewall or SSH mistake stays a five-minute detour instead of a lockout.

1. Sign in and record the baseline

Connect using the address and credentials supplied by the provider:

ssh root@203.0.113.10

Record the Ubuntu release, assigned addresses, storage, and provider recovery method. Check time synchronization and current network listeners:

cat /etc/os-release
timedatectl status
ss -lntup

2. Install updates

Refresh package information and apply available upgrades:

apt update
apt upgrade

Review any packages held back and whether a reboot is required. Do not add third-party repositories until you understand who maintains them and how they receive security updates.

3. Create an administrator

Create a named account and grant Ubuntu’s administrative group:

adduser alice
usermod -aG sudo alice

Replace alice with the real administrator name. Use sudo only for administrative tasks.

4. Install and test the SSH key

From the local computer, copy the public key:

ssh-copy-id alice@203.0.113.10

Open a second terminal and verify that key-based login and sudo work — and keep the original root session open until they do. This one habit prevents nearly every self-inflicted lockout.

ssh alice@203.0.113.10
sudo -v

5. Harden SSH carefully

Create a configuration snippet rather than overwriting the package file:

# /etc/ssh/sshd_config.d/10-hardening.conf
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes

Validate before restarting:

sudo sshd -t
sudo systemctl restart ssh.service

Test another new session before closing existing sessions. Ubuntu warns that an invalid SSH configuration can remove remote access; its OpenSSH guide recommends validation first.

6. Enable the firewall

Allow the current SSH port before enabling UFW:

sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status verbose

Open only ports used by an installed service. Database and administration ports should normally remain private or restricted to trusted networks.

7. Configure updates, monitoring, and backups

Ubuntu Server enables automatic security updates by default on current installations, but verify the configuration and logs. Monitor CPU, memory, disk, network, service health, certificate expiry, and application errors.

Create backups outside the VPS account or failure domain, document retention, and perform a restore test. Provider snapshots are useful, but they should not be the only recovery method for critical data.

8. Verify the baseline

Reboot if required, then confirm non-root SSH, sudo, firewall status, update state, time, disk space, backups, and monitoring. Store the build record and recovery instructions where another authorized administrator can access them.

Sources and further reading

Was this guide helpful?