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
sshbuilt 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:
apt updaterefreshes the package lists.apt full-upgrade -yinstalls all pending updates, including kernel updates.ls /var/run/reboot-requiredtells you whether a reboot is needed. If the file exists, runreboot, wait a minute and log in again.lsb_release -aconfirms 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.
adduser deploycreates the user (replacedeploywith your name). Set a strong password; you will need it forsudo.usermod -aG sudo deployadds the user to the sudo group.- From your laptop, not the server, copy your public key:
ssh-copy-id deploy@SERVER_IP. On Windows PowerShell, wheressh-copy-idis 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" - Open a new terminal and test:
ssh deploy@SERVER_IP, thensudo whoami. It should printroot.
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 noPasswordAuthentication noKbdInteractiveAuthentication noPubkeyAuthentication yesMaxAuthTries 3AllowUsers 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:
sudo sshd -tchecks the syntax. No output means no errors.sudo sshd -T | grep -E "permitrootlogin|passwordauthentication"shows the settings SSH will actually use. Both should sayno.sudo systemctl restart sshapplies the change.- From a new terminal, confirm that
ssh deploy@SERVER_IPstill works and thatssh root@SERVER_IPis 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.
sudo ufw default deny incomingsudo ufw default allow outgoingsudo ufw allow OpenSSH(orsudo ufw allow 2222/tcpif you moved SSH)- Only if this is a web server:
sudo ufw allow 80,443/tcp sudo ufw enablesudo ufw status verboseto 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.
sudo apt install fail2ban -y- Create
/etc/fail2ban/jail.localwith a[sshd]section containingenabled = true,maxretry = 5,findtime = 10mandbantime = 1h. Keep your changes injail.local, because package updates can overwritejail.conf. sudo systemctl enable --now fail2bansudo fail2ban-client status sshdshows 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.
sudo apt install unattended-upgrades -ysudo dpkg-reconfigure --priority=low unattended-upgradesand answer Yes.- Check
/etc/apt/apt.conf.d/20auto-upgrades. Both lines should end in"1". - 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 web01sets a name that makes prompts and logs easy to recognise. Add the same name to/etc/hostsnext to127.0.1.1.sudo timedatectl set-timezone Asia/Kolkataputs logs, cron jobs and backup times in IST, so "the site went down at 2 pm" matches what the logs show.timedatectlshould showSystem 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.
swapon --show. If this prints nothing, there is no swap.sudo fallocate -l 2G /swapfilesudo chmod 600 /swapfilesudo mkswap /swapfileand thensudo swapon /swapfile- To keep it after a reboot, add
/swapfile none swap sw 0 0to/etc/fstab. - To make the kernel prefer RAM, put
vm.swappiness=10in/etc/sysctl.d/99-swappiness.confand runsudo 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.
| Check | Command | What good looks like |
|---|---|---|
| Open ports | sudo ss -tulpn | Only SSH (and later your web or app ports) listening on public addresses |
| Firewall | sudo ufw status numbered | Only the rules you added |
| Failed services | systemctl --failed | 0 loaded units listed |
| Disk | df -h | Root filesystem well under 80% used |
| Memory | free -h | Plenty of "available" memory, swap mostly unused |
| Errors since boot | journalctl -p err -b | No repeating errors |
| Recent logins | last -n 10 | Only 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:
- Root password changed, system fully updated, rebooted if required.
- Named sudo user created, SSH key installed, tested in a second terminal.
- Root login, password login and keyboard-interactive login disabled, confirmed with
sshd -T. - ufw enabled: SSH plus only the ports you need; no database ports open.
- fail2ban running with an sshd jail in
jail.local. - unattended-upgrades enabled and tested with a dry run.
- Hostname set, timezone Asia/Kolkata, clock synchronised.
- Swap file in place if RAM is 8 GB or less, swappiness lowered.
- Baseline checks recorded, external uptime monitor added.
- 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.