To set up a VPS server from scratch you need to: connect via SSH as root, create a non-root user, update packages, configure the firewall, and install your project's software stack. You can have a functional, secure VPS in under an hour.
This guide assumes you already have a Linux VPS (Ubuntu 22.04 or Debian 12 are the most recommended), along with the public IP and root password from your provider. If you're still choosing a provider, check our VPS servers guide for a comparison of local and international options available in Mexico.
Step 1: Connect to Your VPS via SSH
Your first connection uses the root user directly. From your local terminal (Linux, macOS, or WSL on Windows):
ssh root@YOUR_PUBLIC_IP
On the first connection you'll see a host authenticity warning. Type yes to accept and save the server's fingerprint. Then enter the password your provider gave you.
Connecting from Windows Without WSL
Download PuTTY or use the native SSH client built into Windows 10/11 (available in PowerShell since 2019). The experience is equivalent.
Step 2: Create a Secure User and Disable Root Login
Always working as root is the number-one mistake new administrators make. A single mistyped command can destroy the whole system. Create a user with sudo privileges and disable root SSH access.
# Create user (replace "myuser" with your preferred name)
adduser myuser
# Add to the sudo group
usermod -aG sudo myuser
# Switch to the new user to verify
su - myuser
# Verify sudo access
sudo whoami
# should output: root
Once confirmed, edit the SSH config to block root login:
sudo nano /etc/ssh/sshd_config
Find PermitRootLogin yes and change it to PermitRootLogin no. Save with Ctrl+O, exit with Ctrl+X, then restart SSH:
sudo systemctl restart sshd
Optional but Recommended: SSH Keys Instead of Passwords
On your local machine, generate a key pair:
ssh-keygen -t ed25519 -C "my-vps"
Copy the public key to the server:
ssh-copy-id myuser@YOUR_PUBLIC_IP
From now on you can connect without a password. For maximum security, also set PasswordAuthentication no in sshd_config.
Step 3: Update the Operating System
Always update before installing any software. This patches known vulnerabilities and ensures the packages you install are compatible with the latest dependencies.
sudo apt update && sudo apt upgrade -y
On CentOS/AlmaLinux/Rocky Linux use dnf update -y instead of apt.
Reboot if the kernel was updated:
sudo reboot
Reconnect after 30–60 seconds.
Step 4: Configure the Firewall (UFW)
A freshly provisioned VPS has all ports open. Lock things down with UFW (Uncomplicated Firewall), which comes pre-installed on Ubuntu.
# Enable UFW
sudo ufw enable
# Allow SSH — do this BEFORE enabling UFW or you'll lock yourself out!
sudo ufw allow OpenSSH
# Allow HTTP and HTTPS if hosting websites
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# Check status
sudo ufw status verbose
If you changed the SSH port from its default (22), adjust the rule accordingly: sudo ufw allow 2222/tcp.
What Else Might You Need to Open?
| Service | Port | UFW Command |
|---|---|---|
| MySQL / MariaDB (remote) | 3306 | sudo ufw allow 3306/tcp |
| PostgreSQL (remote) | 5432 | sudo ufw allow 5432/tcp |
| FTP passive | 21, 20 | sudo ufw allow 20:21/tcp |
| Plesk panel | 8443 | sudo ufw allow 8443/tcp |
| cPanel | 2083, 2087 | sudo ufw allow 2083/tcp |
Golden rule: only open ports you actually need. Every open port is a potential attack surface.
Step 5: Install Your Stack and Deploy Your First Site
With the base server secured, you can install the software your project needs. The most common stacks in Mexico are LAMP (Linux, Apache, MySQL, PHP) and LEMP (Linux, Nginx, MySQL, PHP).
# Example: install LAMP on Ubuntu 22.04
sudo apt install -y apache2 mariadb-server php php-mysql libapache2-mod-php
# Start and enable services
sudo systemctl enable --now apache2 mariadb
# Secure MariaDB (root password, remove anonymous users)
sudo mysql_secure_installation
Verify Apache is responding by opening your public IP in a browser. If you see the Apache welcome page, the server is up.
Point Your Domain to the VPS
In your domain registrar's panel, create an A record pointing to your VPS's public IP. Propagation takes anywhere from a few minutes to 48 hours depending on the TTL.
Get a Free SSL Certificate with Let's Encrypt
sudo apt install -y certbot python3-certbot-apache
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
Certbot auto-renews the certificate every 90 days. Check the timer with sudo systemctl status certbot.timer.
If you need professional help getting your VPS production-ready, the team at elenlace.com offers server setup and administration services for businesses in Mexico.
Key Takeaways
- Always connect via SSH — avoid generic web panels for system-level tasks when possible.
- Create a sudo user and disable root login — this step is non-negotiable.
- Update the OS before installing any software.
- UFW is your first line of defense: enable it from minute one and open only the ports you need.
- Use SSH keys instead of passwords for secure, frictionless access.
- Certbot/Let's Encrypt covers HTTPS for free and renews automatically — there's no excuse not to have SSL.
Ready to take your VPS to the next level? Visit elenlace.com to explore our server management plans — we handle the infrastructure so you can focus on your business.
FAQ
How long does it take to set up a VPS from scratch?
A user with basic Linux experience can have a functional VPS with LAMP, firewall, and SSL running in under an hour by following this guide. If it's your first time, budget 2–3 hours to go at a comfortable pace.
Which Linux distribution is best for a VPS in Mexico?
Ubuntu 22.04 LTS is the most popular choice thanks to its extensive documentation, five-year support window, and compatibility with virtually all available software. Debian 12 is a more conservative but very stable alternative. CentOS Stream and AlmaLinux 9 are solid options if your team already has Red Hat ecosystem experience.
Can I use cPanel on my VPS?
Yes. cPanel installs on CentOS/AlmaLinux or CloudLinux. It requires at least 2 GB of RAM (4 GB recommended) and carries a monthly license fee. It's a good option if you need to manage multiple hosting accounts or prefer a graphical interface over the command line.
What if I lock myself out after changing SSH config?
Most providers offer an emergency console (VNC or web console) in your account's control panel. Access it from there to fix the error in /etc/ssh/sshd_config without needing an active SSH session.
Useful resources
Other providers and guides worth comparing: