Guides

Initial server setup: the first ten minutes on a new VPS

A repeatable checklist for a fresh Ubuntu or Debian server: non-root user, key-only SSH, firewall, automatic security updates, hostname, timezone and swap.

Published ~7 min read
On this page

A fresh VPS boots as a single root account reachable by password: fine for the first login, wrong for anything after. These are the first ten minutes on a new server: create a real user, lock down SSH, turn on a firewall and enable automatic security updates. The commands below assume Ubuntu or Debian; the RHEL equivalents are noted where they differ.

  1. 1Log in and update
    first login
    ssh root@your-server-ip
    apt update && apt upgrade -y      # dnf upgrade -y on RHEL
  2. 2Create a non-root user with sudo

    Working as root full-time turns every typo into a potential disaster.

    new admin user
    adduser deploy
    usermod -aG sudo deploy        # -aG wheel on RHEL
  3. 3Set up key-based SSH for that user

    From your local machine, copy your public key to the new account:

    from your laptop
    ssh-copy-id deploy@your-server-ip
    ssh deploy@your-server-ip      # confirm it works before going further
  4. 4Disable root login and passwords over SSH

    Only once key login works, harden the daemon:

    /etc/ssh/sshd_config
    PermitRootLogin no
    PasswordAuthentication no
    # then
    sudo sshd -t && sudo systemctl restart ssh
  5. 5Turn on a firewall
    ufw
    sudo ufw allow OpenSSH
    sudo ufw enable
    sudo ufw status
  6. 6Enable automatic security updates
    unattended-upgrades
    sudo apt install -y unattended-upgrades
    sudo dpkg-reconfigure -plow unattended-upgrades

Two more worthwhile minutes

hostname, time, swap
sudo hostnamectl set-hostname web-01
sudo timedatectl set-timezone Europe/Berlin

# small servers benefit from a little swap
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

What comes next

Every VMHeaven KVM plan deploys a clean Ubuntu, Debian or Rocky image in about a minute with a browser VNC console in the panel, so on a Linux server you can run through this checklist and never fear a lockout.

Frequently asked

What is the single most important first step?

Create a non-root user with sudo and switch to key-based SSH for it, then disable root login and passwords. That removes the biggest risk on a fresh box.

How do I avoid locking myself out while hardening SSH?

Keep your current session open and test the new login in a second terminal before closing the first. On a VPS with console access, even a mistake is recoverable.

Do small servers need swap?

A small swap file (1–2 GB) is cheap insurance against out-of-memory kills on low-RAM instances. It is not a substitute for enough RAM, but it smooths spikes.

Related articles

All guides

Create a sudo user on Ubuntu, Debian and Rocky Linux, and fix 'is not in the sudoers file'

Add a user with adduser, grant sudo through the sudo or wheel group, test it safely and fix 'user is not in the sudoers file' without locking yourself out.

ssh-copy-id: copy your SSH key to a server, plus the Windows equivalent

ssh-copy-id -i ~/.ssh/id_ed25519.pub user@host adds your key to authorized_keys on the server. Every option, a PowerShell version for Windows, and fixes.

Change the SSH port on Ubuntu 24.04, Debian and Rocky without locking yourself out

Open the new port first, edit sshd_config, and on Ubuntu 24.04 restart ssh.socket, or the change silently does nothing. Plus SELinux on Rocky Linux.

Install Docker on Ubuntu 24.04 and Debian 12/13 from the official repository

Install Docker Engine and Compose from Docker's apt repository on Ubuntu 24.04 or Debian 12/13, run it without sudo and stop it bypassing your firewall.

tmux cheat sheet: sessions, windows, panes and the keys you actually use

The tmux keys and commands used every day: Ctrl-b bindings for windows and panes, detaching and reattaching a session, copy mode, and a minimal .tmux.conf.

How to exit vim: :wq, :q! and every other way out

Esc then :wq saves and quits; :q! quits without saving. Every exit command, why vim traps people in the first place, and how to change the default editor.

Change the hostname on Ubuntu (and Debian or Rocky Linux) without a reboot

Ubuntu change hostname: sudo hostnamectl set-hostname NAME, update the 127.0.1.1 line in /etc/hosts and stop cloud-init reverting it. Debian and Rocky too.

Linux date and timezone: date formats, timedatectl and setting the clock

Set the date in Linux, format it (+%F %T, +%s, ISO 8601) and convert with date -d; change the timezone with timedatectl, plus NTP and why servers use UTC.

How to switch user in Linux: su, su - and sudo -i, with the errors fixed

Switch user in Linux with su - USERNAME, or sudo -i on Ubuntu with root locked. su vs su - vs sudo tested, su: Authentication failure and nologin fixed.