Back to articles
Cloud VPS HostingAvertHostNovember 16, 202611 min read

How to Set Up a VPS: The First 30 Minutes on Ubuntu

A step-by-step checklist for the first 30 minutes on a new Ubuntu VPS: sudo user and SSH keys, SSH hardening, ufw and fail2ban, automatic security updates, IST timezone, swap and a baseline snapshot.

If you want to know how to set up VPS servers properly, the first 30 minutes matter most. Log in once as root, create a named sudo user with an SSH key, switch off password and root logins, turn on a firewall, add fail2ban and automatic security updates, then set the timezone, swap and a baseline snapshot. This guide walks through each step on Ubuntu 22.04 or 24.04 LTS, with the exact commands and a check after each one, so you never lock yourself out.

It is written for developers, freelancers and small IT teams in India who have just deployed a Linux cloud VPS and see an IP address and a root password in their dashboard. If you have not chosen a plan yet, read how to choose the right Linux VPS plan first.

Before you start: what you need

Collect these before you open a terminal. It saves a lot of back and forth later.

  • The server's public IPv4 address (and IPv6, if one is assigned) and the initial root password or SSH key from your provider's panel.
  • An SSH client. Linux and macOS have ssh built in. On Windows 10 and 11, OpenSSH is built into PowerShell and Windows Terminal, so you do not need PuTTY.
  • An SSH key pair on your laptop. If you do not have one, create it now: ssh-keygen -t ed25519 -C "you@yourcompany.in". Accept the default path and set a passphrase.
  • Access to the provider's web console (VNC or serial console). It is your way back in if a firewall or SSH change goes wrong.
  • A note of what will run on the server (website, API, database, staging). That decides which ports you open later.

Pick the data centre closest to your users when you deploy. For an audience in India, a server in India keeps round-trip times low for every page load and every SSH keystroke. You can check it from your office with ping -c 20 SERVER_IP, or mtr -rwc 50 SERVER_IP to see each network hop and any packet loss.

First login, updates and a sudo user

Log in and update the system

Connect as root using the address from your panel:

  • ssh root@SERVER_IP

The first time, SSH asks you to confirm the host key fingerprint. If your provider shows the fingerprint in the panel or console, compare it before you type yes.

Then bring the system fully up to date before you install anything else:

  1. apt update refreshes the package lists.
  2. apt full-upgrade -y installs all pending updates, including kernel updates.
  3. ls /var/run/reboot-required tells you whether a reboot is needed. If the file exists, run reboot, wait a minute and log in again.
  4. lsb_release -a confirms the Ubuntu release you are on.

If you are given a root password rather than a key, change it straight away with passwd. Panel-generated passwords are often sent by email, and you should assume that copy is not private.

Create a sudo user and set up SSH keys

Working as root all day means one mistyped command can wipe the server, and every log line shows "root" instead of a person. Create a named user for each human who needs access.

  1. adduser deploy creates the user (replace deploy with your name). Set a strong password; you will need it for sudo.
  2. usermod -aG sudo deploy adds the user to the sudo group.
  3. From your laptop, not the server, copy your public key: ssh-copy-id deploy@SERVER_IP. On Windows PowerShell, where ssh-copy-id is not available, run: type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh deploy@SERVER_IP "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
  4. Open a new terminal and test: ssh deploy@SERVER_IP, then sudo whoami. It should print root.

Keep the original root session open until the new login and sudo both work. This one habit prevents most lockouts.

If several people share the server, give each person their own user and key. When someone leaves, you delete one user (sudo deluser --remove-home name) instead of changing a shared password everywhere.

Harden SSH

Bots scan every public IPv4 address for SSH and try common passwords continuously. Once key login works, switch password login off completely.

On current Ubuntu releases, the cleanest way is a small drop-in file rather than editing the main config. Create /etc/ssh/sshd_config.d/10-hardening.conf with sudo nano and add:

  • PermitRootLogin no
  • PasswordAuthentication no
  • KbdInteractiveAuthentication no
  • PubkeyAuthentication yes
  • MaxAuthTries 3
  • AllowUsers deploy (list every user who may log in, separated by spaces)

Watch out for one common trap. Cloud images often ship a file such as /etc/ssh/sshd_config.d/50-cloud-init.conf that contains PasswordAuthentication yes. Within the drop-in directory, the first value read for a setting wins, and files are read in name order, which is why the file above starts with 10-. Check what is there with grep -r PasswordAuthentication /etc/ssh/sshd_config /etc/ssh/sshd_config.d/.

Then validate and apply:

  1. sudo sshd -t checks the syntax. No output means no errors.
  2. sudo sshd -T | grep -E "permitrootlogin|passwordauthentication" shows the settings SSH will actually use. Both should say no.
  3. sudo systemctl restart ssh applies the change.
  4. From a new terminal, confirm that ssh deploy@SERVER_IP still works and that ssh root@SERVER_IP is refused.

Changing the SSH port from 22 reduces log noise but is not real security. If you do change it, open the new port in the firewall first. The Ubuntu OpenSSH server documentation lists the other options.

Firewall, fail2ban and automatic security updates

Firewall with ufw

Ubuntu ships ufw (Uncomplicated Firewall). The rule is simple: deny everything incoming, then allow only the services you run. Order matters. Allow SSH before you enable the firewall.

  1. sudo ufw default deny incoming
  2. sudo ufw default allow outgoing
  3. sudo ufw allow OpenSSH (or sudo ufw allow 2222/tcp if you moved SSH)
  4. Only if this is a web server: sudo ufw allow 80,443/tcp
  5. sudo ufw enable
  6. sudo ufw status verbose to review the result.

If your office has a fixed IP, restrict SSH to it: sudo ufw allow from OFFICE_IP to any port 22 proto tcp, then remove the general rule with sudo ufw delete allow OpenSSH. Never open database ports such as 3306 (MySQL) or 5432 (PostgreSQL) to the internet. Apps on the same server connect over localhost, and remote admin can go through an SSH tunnel. Check that IPV6=yes is set in /etc/default/ufw so the same rules cover IPv6. The Ubuntu firewall guide covers more advanced rules.

Brute-force protection with fail2ban

fail2ban reads the logs and temporarily bans IP addresses that keep failing to log in.

  1. sudo apt install fail2ban -y
  2. Create /etc/fail2ban/jail.local with a [sshd] section containing enabled = true, maxretry = 5, findtime = 10m and bantime = 1h. Keep your changes in jail.local, because package updates can overwrite jail.conf.
  3. sudo systemctl enable --now fail2ban
  4. sudo fail2ban-client status sshd shows how many IPs are currently banned.

With password login disabled, fail2ban is a second layer. It mainly keeps logs readable and stops scanners from using your CPU.

Automatic security updates

Most servers that get compromised were simply never patched. Ubuntu can install security updates on its own every day.

  1. sudo apt install unattended-upgrades -y
  2. sudo dpkg-reconfigure --priority=low unattended-upgrades and answer Yes.
  3. Check /etc/apt/apt.conf.d/20auto-upgrades. Both lines should end in "1".
  4. Do a test run: sudo unattended-upgrade --dry-run --debug

By default only the security pocket is upgraded automatically, which is the right balance for most production servers. Kernel updates still need a reboot. You can let the server reboot itself at a quiet time by setting Unattended-Upgrade::Automatic-Reboot "true"; and Unattended-Upgrade::Automatic-Reboot-Time "03:30"; in /etc/apt/apt.conf.d/50unattended-upgrades. Do this only if your application restarts cleanly after a reboot. The Ubuntu automatic updates guide explains every option.

Hostname, IST timezone, time sync and swap

Hostname and timezone

  • sudo hostnamectl set-hostname web01 sets a name that makes prompts and logs easy to recognise. Add the same name to /etc/hosts next to 127.0.1.1.
  • sudo timedatectl set-timezone Asia/Kolkata puts logs, cron jobs and backup times in IST, so "the site went down at 2 pm" matches what the logs show.
  • timedatectl should show System clock synchronized: yes. Correct time matters for TLS certificates, log correlation and two-factor codes.

Swap

Many cloud images have no swap. On a small VPS, a short memory spike from a package update or a database query can then trigger the out-of-memory killer and stop MySQL or your app. A modest swap file gives you a safety margin. It is not a substitute for enough RAM.

  1. swapon --show. If this prints nothing, there is no swap.
  2. sudo fallocate -l 2G /swapfile
  3. sudo chmod 600 /swapfile
  4. sudo mkswap /swapfile and then sudo swapon /swapfile
  5. To keep it after a reboot, add /swapfile none swap sw 0 0 to /etc/fstab.
  6. To make the kernel prefer RAM, put vm.swappiness=10 in /etc/sysctl.d/99-swappiness.conf and run sudo sysctl --system.

If free -h shows swap in steady use day after day, the server needs more RAM. Resize it rather than adding more swap.

Baseline checks, a first snapshot and the 30-minute checklist

Before you install your application, record a clean baseline. You will compare against it when something feels slow later.

CheckCommandWhat good looks like
Open portssudo ss -tulpnOnly SSH (and later your web or app ports) listening on public addresses
Firewallsudo ufw status numberedOnly the rules you added
Failed servicessystemctl --failed0 loaded units listed
Diskdf -hRoot filesystem well under 80% used
Memoryfree -hPlenty of "available" memory, swap mostly unused
Errors since bootjournalctl -p err -bNo repeating errors
Recent loginslast -n 10Only your own users and IPs

Install htop for a live view of CPU and memory, and set up an external uptime monitor that checks your site or port from outside your server. A monitor running on the same server cannot tell you when the server itself is down.

Finally, take a snapshot in the provider's panel and name it something like baseline-2026-ubuntu-hardened. If an install goes wrong later, you can roll back to a clean, secured server in minutes instead of repeating this guide. Remember that a snapshot is not a backup strategy. Your application data needs its own scheduled, tested backups, as covered in our cloud backup strategy guide.

A note on personal data

If the server will store customer names, phone numbers or other personal data, the Digital Personal Data Protection Act, 2023 expects you to take reasonable security safeguards. The steps above (named users, key-only login, a firewall, patching and logs kept in IST) are the practical foundation. Write down who has access and where each copy of the data lives. Ask your CA or lawyer which other obligations apply to your business.

The 30-minute checklist

Print this or keep it in your team's wiki and tick it off for every new server:

  1. Root password changed, system fully updated, rebooted if required.
  2. Named sudo user created, SSH key installed, tested in a second terminal.
  3. Root login, password login and keyboard-interactive login disabled, confirmed with sshd -T.
  4. ufw enabled: SSH plus only the ports you need; no database ports open.
  5. fail2ban running with an sshd jail in jail.local.
  6. unattended-upgrades enabled and tested with a dry run.
  7. Hostname set, timezone Asia/Kolkata, clock synchronised.
  8. Swap file in place if RAM is 8 GB or less, swappiness lowered.
  9. Baseline checks recorded, external uptime monitor added.
  10. Baseline snapshot taken and named.

Setting up a Windows server instead? The steps are different: Remote Desktop, Network Level Authentication and account lockout. They are covered in our guide to Windows VPS with RDP.

How AvertHost can help

AvertHost Linux cloud VPS plans run in a Tier-IV data centre in Delhi, so your server and its data stay in India, close to Indian users. You get root access and can deploy Ubuntu, CentOS or Debian, on NVMe storage with a separate NVMe backup volume. Each plan includes a dedicated IP with IPv6 support and DDoS protection, and the platform is backed by a 99.9% uptime SLA. You can choose hourly billing for test servers like the one in this guide, or monthly billing for production. Billing is in INR with GST invoices.

Our 24/7 support team is based in India. If you are stuck at any step, for example locked out after an SSH change, they can help you get back in.

FAQ

How long does it take to set up a VPS?

Deploying the server from a provider's panel usually takes a few minutes. The hardening steps in this guide take about 30 minutes the first time and around 10 once you have done them a couple of times. After that, installing your web server or application is a separate step.

I locked myself out after changing SSH or the firewall. What now?

Open the web console (VNC or serial console) in your provider's panel. It works even when SSH is blocked. Log in with your user's password, then fix the file in /etc/ssh/sshd_config.d/ or run sudo ufw allow OpenSSH. If you cannot log in at all, restore the snapshot you took before the change.

Should I use Ubuntu, Debian or CentOS for my first VPS?

For most first-time users, an Ubuntu LTS release is the easiest choice. It has the largest amount of tutorials, long security support and current packages. Debian is very similar and slightly more conservative. Choose a RHEL-family system such as CentOS Stream if your software vendor or team specifically supports it. The commands differ: dnf instead of apt, and firewalld instead of ufw.

Do I need a control panel to manage a VPS?

No. Everything in this guide is done over SSH. A control panel can make hosting several websites easier, but it adds licence cost, memory use and more software to keep patched. Many developers run a single application without one.