You just bought a VPS. The provider emailed you an IP address, a root password, and maybe a link to their control panel. Now what?
Most teams skip the hardening steps and go straight to installing their application, then wonder why the server gets compromised or mysteriously fails three months later. A proper VPS hosting setup guide walks you through the security, deployment, and monitoring configuration in a logical order so you don't have to backtrack later.
This is the exact eight-step sequence I follow after spinning up a new VPS, whether it's for a client site or an internal tool. Nothing here is optional.
Step 1: Initial SSH access and user setup
Your provider gave you a root password. Log in once to create a non-root user with sudo privileges, then disable direct root login entirely.
ssh root@your_server_ip
adduser deploy
usermod -aG sudo deploy
Pick a strong password for the deploy user. Open a second terminal and test sudo access before you log out of the root session—if you lock yourself out now, you'll need the provider's console.
ssh deploy@your_server_ip
sudo apt update
If that works, you're ready to harden SSH.
Step 2: Harden SSH and disable password authentication
SSH brute-force scanners hit every public IP within hours. Password authentication is the weakest link.
Generate an SSH key pair on your local machine if you don't already have one:
ssh-keygen -t ed25519 -C "[email protected]"
Copy the public key to the server:
ssh-copy-id -i ~/.ssh/id_ed25519.pub deploy@your_server_ip
Test key-based login in a new terminal before you disable passwords. Once confirmed, edit /etc/ssh/sshd_config:
sudo nano /etc/ssh/sshd_config
Change these lines:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
Restart SSH:
sudo systemctl restart sshd
From this point forward, only your key will unlock the server. Store the private key securely and back it up—losing it means console recovery.
In support tickets I handled, half the "I'm locked out" cases traced back to disabling passwords without testing key auth first. Don't skip the test.
Step 3: Configure the firewall (UFW or iptables)
A fresh VPS usually has no firewall rules, so every port is open. Lock it down before you install anything.
Ubuntu and Debian users can use UFW:
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow ssh
sudo ufw enable
If your application will serve HTTP/HTTPS traffic, open those ports:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
For a database server that only your app server should reach, allow the specific port only from the app server's IP:
sudo ufw allow from app_server_ip to any port 5432 proto tcp
Check the active rules:
sudo ufw status numbered
If you prefer iptables directly, the logic is the same: default deny, then whitelist only what you need. Keep the rules minimal—complex firewall configs are harder to audit and often hide misconfigurations.
Step 4: Update the system and enable automatic security patches
Outdated packages are the second most common entry point after weak SSH config. Run a full update immediately:
sudo apt update && sudo apt upgrade -y
Then enable unattended security updates so you don't have to remember:
sudo apt install unattended-upgrades -y
sudo dpkg-reconfigure --priority=low unattended-upgrades
Select "Yes" when prompted. Check the configuration in /etc/apt/apt.conf.d/50unattended-upgrades if you want to review what gets auto-updated—by default it's security patches only, which is what you want.
Reboot if the kernel was updated:
sudo reboot
Some providers require you to reboot from their control panel. Check your provider's docs if the reboot command doesn't work.
Step 5: Install a web server and configure TLS
Most VPS setups serve HTTP traffic. Pick Nginx or Apache depending on what you know, then get a Let's Encrypt certificate before you deploy your app.
For Nginx on Ubuntu:
sudo apt install nginx certbot python3-certbot-nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx
Point your domain's A record to the VPS IP, wait for DNS propagation (usually under five minutes), then request a certificate:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
Certbot will modify your Nginx config to redirect HTTP to HTTPS and set up auto-renewal. Test renewal:
sudo certbot renew --dry-run
If that succeeds, your certificates will renew automatically every sixty days. If it fails, check your DNS records and firewall rules—port 80 must be open for the ACME challenge.
So what if your app needs something other than a web server?
The same principle applies. Install only what the application requires, verify it starts on boot, and lock down the ports. For a database-only VPS, skip Nginx and install PostgreSQL or MySQL instead:
sudo apt install postgresql -y
sudo systemctl enable postgresql
Change the default postgres user password immediately:
sudo -u postgres psql
\password postgres
Then configure PostgreSQL to accept connections only from your app server's IP by editing /etc/postgresql/*/main/pg_hba.conf and /etc/postgresql/*/main/postgresql.conf. Restart the service after changes:
sudo systemctl restart postgresql
Always verify the service starts cleanly:
sudo systemctl status postgresql
Step 6: Deploy your application
How you deploy depends on your stack. For a Node.js app, you'll typically clone the repo, install dependencies, and run it behind a process manager like PM2:
sudo apt install nodejs npm -y
sudo npm install -g pm2
git clone https://github.com/youruser/yourapp.git
cd yourapp
npm install
pm2 start app.js --name "yourapp"
pm2 startup systemd
pm2 save
For Python apps, use systemd or Supervisor. For PHP, configure php-fpm and point Nginx to the document root.
The key is to run the application as a non-root user, use a process manager that restarts on failure, and configure it to start on boot. Test a reboot to make sure everything comes back up:
sudo reboot
After the reboot, SSH back in and verify your app is running:
pm2 status
curl http://localhost:3000
If the app is healthy locally but not accessible externally, check your firewall rules and Nginx proxy config.
Step 7: Set up monitoring and log aggregation
You won't know the server is down until a user complains unless you configure uptime monitoring. At minimum, use a free service to ping your application every few minutes.
For server-level monitoring, install a lightweight agent. Many teams use Netdata for real-time metrics:
bash <(curl -Ss https://my-netdata.io/kickstart.sh)
Netdata runs on port 19999 by default. You can reverse-proxy it through Nginx and add basic auth, or use SSH tunneling to access it securely:
ssh -L 19999:localhost:19999 deploy@your_server_ip
Then open http://localhost:19999 in your browser.
For log aggregation, centralize logs early. If you run multiple VPS instances, ship logs to a central location using rsyslog, Loki, or a managed service. Even on a single VPS, configure log rotation so you don't fill the disk:
sudo nano /etc/logrotate.d/yourapp
Example config:
/var/log/yourapp/*.log {
daily
missingok
rotate 14
compress
notifempty
create 0640 deploy deploy
}
Test it:
sudo logrotate -f /etc/logrotate.d/yourapp
Check disk usage regularly:
df -h
du -sh /var/log/*
Full disks are the number one cause of mysterious application failures that "just started happening."
Step 8: Document access, backups, and runbooks
The setup isn't done until someone else can log in, troubleshoot, and restore from backup without asking you.
Create a simple runbook in your team wiki or a README in your infrastructure repo. Include:
- SSH access instructions (where the key lives, which user to log in as)
- Firewall rules and why each port is open
- Application start/stop/restart commands
- Log file locations
- Backup schedule and restore procedure
For backups, snapshot the VPS at the provider level if they offer it, or use a tool like rsync, borg, or restic to back up critical directories to object storage. Test a restore at least once—untested backups are not backups.
A basic rsync backup script:
#!/bin/bash
rsync -avz --delete /var/www/ backup_user@backup_server:/backups/vps1/www/
rsync -avz --delete /etc/ backup_user@backup_server:/backups/vps1/etc/
Schedule it with cron:
crontab -e
Add:
0 2 * * * /home/deploy/backup.sh
That runs the backup daily at 2 AM. Verify the cron job is active:
crontab -l
Store the backup credentials securely and document the restore procedure step by step.
FAQ
How long does a full VPS hosting setup take?
Between one and three hours for the initial hardening, deployment, and monitoring config. Backups and documentation add another hour.
Can I skip the firewall step if the provider has one?
No. Provider firewalls are a second layer, not a replacement for host-based rules. Configure both.
What if I need to allow a port temporarily?
Use sudo ufw allow <port> to open it, then sudo ufw delete allow <port> when you're done. Always close temporary rules.
How do I know if automatic updates broke something?
Check /var/log/unattended-upgrades/ for the update log. If an update caused an issue, you can pin the package version or disable unattended upgrades for that package only.
Should I use a control panel like cPanel or Plesk on a VPS?
Only if your team doesn't have command-line experience. Control panels add overhead and another layer to troubleshoot. For hosting support engineers and sysadmins, direct CLI management is faster and more transparent.
What to lock down before going live
You can install your application before hardening, but you shouldn't expose it to the internet until SSH is locked down, the firewall is active, and monitoring is in place. That's the minimum.
The setup sequence in this guide is the order I follow because each step builds on the previous one: user access first, then SSH hardening, then firewall, then updates, then the application stack, then TLS, then deployment, then monitoring. Skipping or reordering steps usually means backtracking.
Once the VPS is in production, the real work is operational: watching logs, responding to alerts, applying updates, and refining firewall rules as your application evolves. But if you follow these eight steps from the start, you'll have a solid foundation that doesn't wake you up at 3 AM because someone guessed your root password.
