
Hello! If you’re new to servers and just got your first VPS (Virtual Private Server), congratulations — you’re about to set up a powerful, secure machine you can use for websites, apps, bots, databases, or anything else.
This guide is written especially for beginners. I’ll explain every single step in simple words: why we do it, what it means, what could go wrong if we skip it, and exactly what to type (copy-paste friendly). No complicated jargon without explanation.
We’re using Ubuntu 24.04 LTS (Noble Numbat) — the latest long-term support version in 2026. It gets security updates automatically until May 2029 (5 years standard, longer with Ubuntu Pro). It’s stable, free, and loved by millions.
Time needed: About 20–40 minutes if you follow slowly. What you’ll need: Your VPS login details (IP address + root password or SSH key from your provider like DigitalOcean, Vultr, Linode, Contabo, etc.).
Let’s go step by step!
Table of Contents
- 1 Why Choose Ubuntu 24.04 LTS for Your VPS in 2026?
- 2 1. Deploying Ubuntu 24.04 on Your VPS (Creating the Server)
- 3 2. Initial Login & Basic Security (First Connection)
- 4 3. Create a Secure Non-Root User with Sudo (Very Important!)
- 5 4. Hardening SSH – Make Login Super Secure
- 6 SparkCreate Business Tools
- 7 5. Set Up Firewall with UFW (Block Unwanted Visitors)
- 8 6. Install & Configure Fail2Ban (Auto-Ban Bad Guys)
- 9 7. Enable Automatic Security Updates
- 10 8. Set Up Swap Memory (Prevent Crashes on Low-RAM VPS)
- 11 9. Additional Easy Best Practices
- 12 10. Next Steps – What to Do Now?
- 13 Conclusion
- 14 FAQ
Why Choose Ubuntu 24.04 LTS for Your VPS in 2026?
- It has a modern Linux kernel (better speed & hardware support)
- Gets free security fixes until 2029 — no rush to upgrade soon
- Huge community help — if you get stuck, answers are everywhere
- Works perfectly on cheap VPS plans (even 1 CPU + 1–2 GB RAM)
Quick note: These steps work the same whether your VPS is in Nigeria, Europe, USA, or anywhere. Just choose a provider with good speed to your location.
1. Deploying Ubuntu 24.04 on Your VPS (Creating the Server)
This is done in your VPS provider’s website (not on your computer yet).
- Log in to your provider (e.g., DigitalOcean dashboard, Vultr panel).
- Click “Create” → “Droplet / Instance / VPS”.
- Choose Ubuntu 24.04 LTS (x64) — make sure it’s the Server version (no desktop/GUI).
- Pick a small plan to start (1 vCPU + 1–2 GB RAM is fine for learning).
- Authentication:
- Best choice: SSH key (more secure — we’ll explain later). Upload your public key if you have one.
- Alternative: Set a very strong root password (provider emails it to you).
- Click “Create” or “Deploy”. Wait 30–90 seconds.
- Copy the IP address shown (looks like 123.45.67.89).
Why this matters: This gives you a fresh, empty Ubuntu server in the cloud. Think of it like renting a computer that runs 24/7.
2. Initial Login & Basic Security (First Connection)
Now we connect from your computer to the server.
Open a terminal/command prompt on your own computer:
- Windows: Use PowerShell, Git Bash, or Windows Terminal (install OpenSSH if needed).
- macOS/Linux: Just open Terminal.
Type this (replace with your real IP):
ssh root@your-vps-ip- First time: It asks “Are you sure you want to continue connecting?” → Type yes and Enter.
- Password: Paste/type the root password your provider gave you (characters won’t show — normal).
You’re now inside your server as the powerful “root” user!
First thing — always update (makes your server safer and faster):
apt update && apt upgrade -y && apt autoremove -y- apt update → checks for new package lists
- apt upgrade -y → installs newest versions (security fixes!)
- apt autoremove -y → removes old unused files
If it asks to reboot (rare), do it:
rebootWait 30 seconds, then reconnect with the same ssh command.
Set correct timezone (so logs show right time — important for debugging):
timedatectl set-timezone Africa/Lagos # Change to your city, e.g. Europe/London, America/New_York
timedatectl status # Check it workedSet a friendly hostname (server name — helps when you have multiple):
hostnamectl set-hostname my-first-server # Pick any name you like
nano /etc/hostsInside the file, scroll down and add this line:
127.0.1.1 my-first-server
Press Ctrl+O → Enter → Ctrl+X to save and exit.
Why? Updates keep bad guys out. Timezone makes logs readable. Hostname makes your server feel like “yours”.
3. Create a Secure Non-Root User with Sudo (Very Important!)
Root is like the god account — too dangerous to use every day. Hackers love attacking root.
Instead, we’ll make a normal user who can become root only when needed (using sudo).
adduser yourname # Replace 'yourname' with something you like, e.g. adminuser- It asks for password → make a strong one (different from root!).
- Other questions (full name, etc.) → just press Enter to skip.
Give this user superpowers:
usermod -aG sudo yournameLog out:
exitReconnect as the new user:
ssh yourname@your-vps-ipTest you can use sudo:
sudo apt updateIf it asks for your password — enter it.
From now on: Always log in as this user. Use sudo before commands that need power.
Why this is huge for security: If someone guesses your password, they only get normal-user access — not full root control.
4. Hardening SSH – Make Login Super Secure
SSH is how you connect. By default, it’s okay — but we can make it much harder for attackers.
First, on your own computer (not the server), create your SSH key pair (like a super-secure passwordless key):
ssh-keygen -t ed25519 -C "[email protected]"- Press Enter for default location (/home/yourname/.ssh/id_ed25519 or C:\Users\YourName.ssh\id_ed25519 on Windows).
- Passphrase: Optional but good — adds extra protection (like a PIN for the key).
The keys are saved automatically in a hidden .ssh folder in your home directory:
- Private key (secret!): ~/.ssh/id_ed25519 — never send this anywhere
- Public key (safe to share): ~/.ssh/id_ed25519.pub
Now copy the public key to your server:
ssh-copy-id yourname@your-vps-ip(Or if that doesn’t work: On your computer run cat ~/.ssh/id_ed25519.pub, copy the output, then on server: mkdir -p ~/.ssh && nano ~/.ssh/authorized_keys, paste, save.)
Back on server (as yourname user):
sudo nano /etc/ssh/sshd_configFind/change these lines (remove # if present):
PermitRootLogin no # No more root login over SSH
PasswordAuthentication no # Only keys allowed — no passwords
PubkeyAuthentication yesOptional (extra hiding from bots): Change port from 22
Port 2222Save (Ctrl+O → Enter → Ctrl+X).
Restart SSH:
sudo systemctl restart sshSuper important warning for beginners:
Do NOT close your current terminal yet!
Open a second terminal window on your computer and test:
ssh -p 2222 yourname@your-vps-ip # Use -p 2222 only if you changed the portIf it connects without password (or with your key passphrase) → success!
Now it’s safe to close the first window.
Why? Passwords can be guessed. Keys are almost impossible to crack. Disabling root stops most automated attacks.
5. Set Up Firewall with UFW (Block Unwanted Visitors)
Think of UFW as a door guard — only let in what you allow.
sudo apt install ufw -yAllow your SSH (use new port if changed):
sudo ufw allow OpenSSH # or: sudo ufw allow 2222/tcpSet rules:
sudo ufw default deny incoming # Block everything coming in by default
sudo ufw default allow outgoing # Allow your server to talk out
sudo ufw enableType y to continue.
Check:
sudo ufw status verboseLater (when you install Nginx/Apache): sudo ufw allow ‘Nginx Full’ or sudo ufw allow 80,443/tcp
Why? Without this, anyone on the internet can try to connect to dangerous ports.
6. Install & Configure Fail2Ban (Auto-Ban Bad Guys)
Fail2Ban watches logs and bans IPs that try too many wrong logins.
sudo apt install fail2ban -yCreate simple config:
sudo nano /etc/fail2ban/jail.localPaste:
[sshd]
enabled = true
port = 2222 # Change if you used different port
maxretry = 5
bantime = 3600
findtime = 600
ignoreip = 127.0.0.1/8 your-home-ip # Add your own IP so you can't ban yourself!Save & restart:
sudo systemctl restart fail2ban
sudo fail2ban-client status sshdWhy? Stops brute-force attacks (thousands of tries per minute).
7. Enable Automatic Security Updates
Let Ubuntu install security fixes by itself.
sudo apt install unattended-upgrades -yCheck config:
sudo nano /etc/apt/apt.conf.d/50unattended-upgradesMake sure these are not commented (# removed):
"${distro_id}:${distro_codename}-security";
"${distro_id}:${distro_codename}-updates";Enable:
sudo dpkg-reconfigure --priority=low unattended-upgradesChoose Yes.
Why? You don’t have to remember to update — security patches install automatically.
8. Set Up Swap Memory (Prevent Crashes on Low-RAM VPS)
If your VPS has little RAM (1–2 GB), it can freeze when busy. Swap is like emergency memory on disk.
Check current:
free -hFor 1–2 GB RAM VPS → make 2 GB swap (safe size).
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfileMake permanent:
sudo nano /etc/fstabAdd at end:
/swapfile none swap sw 0 0Tune swappiness (use RAM more, swap less):
sudo sysctl vm.swappiness=10
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
sudo sysctl -pCheck:
free -hWhy? Prevents “out of memory” crashes during updates or traffic.
9. Additional Easy Best Practices
Install monitoring tools (see what’s happening):
sudo apt install htop glances -y- Run htop → nice colorful view of CPU/RAM
- Run glances → even more info (press q to quit)
Time sync (keep clock accurate):
sudo timedatectl set-ntp trueClean old logs:
sudo journalctl --vacuum-time=2weeksBackups: Use your provider’s snapshot button weekly — it’s easy and free/cheap.
10. Next Steps – What to Do Now?
Your server is secure and ready!
Popular next:
- Web server: sudo apt install nginx
- Free SSL: Install certbot later
- Docker: For apps/containers
- WordPress/Node/Python: Many guides online
Conclusion
You did it! Your Ubuntu 24.04 VPS is now much safer than when it arrived. You learned:
- Never use root daily
- Use SSH keys
- Firewall on
- Auto-updates
- Swap for stability
Keep learning — run sudo apt update && sudo apt upgrade -y weekly (or let auto-updates handle it).
Questions? Comment below — I’ll help! Share if this helped you. 🚀
FAQ
I changed SSH port and can’t connect! Use provider console to fix /etc/ssh/sshd_config and restart ssh.
Is 24.04 better than 22.04? Yes for new servers — longer support, newer features.
Can I add More security later? Yes — ClamAV (antivirus), AppArmor checks, 2FA with Google Authenticator, etc.
How much swap is recommended? 2 GB is safe start. If swap is always full → upgrade RAM.
Happy and secure server! 😊