All tutorials
VPS & LinuxIntermediate

Set Up and Secure a New Ubuntu VPS

Create a sudo user, configure SSH keys, enable a firewall and automatic security updates on your first VPS.

Hostn.ME Team 10 min read 20 viewsUpdated November 22, 2026

A fresh VPS is exposed to the internet immediately. Spend 10 minutes on these steps before deploying anything.

1. Log in and update

ssh root@YOUR_SERVER_IP
apt update && apt upgrade -y

2. Create a non-root user

adduser deploy
usermod -aG sudo deploy

3. Use SSH keys instead of passwords

On your computer:

ssh-keygen -t ed25519 -C "[email protected]"
ssh-copy-id deploy@YOUR_SERVER_IP

Then on the server, edit /etc/ssh/sshd_config:

PermitRootLogin no
PasswordAuthentication no
sudo systemctl restart ssh

⚠️ Keep your current session open and test logging in from a new terminal before closing it.

4. Enable the firewall

sudo ufw allow OpenSSH
sudo ufw allow 80,443/tcp
sudo ufw enable
sudo ufw status

5. Automatic security updates

sudo apt install unattended-upgrades -y
sudo dpkg-reconfigure --priority=low unattended-upgrades

6. Block brute-force attempts

sudo apt install fail2ban -y
sudo systemctl enable --now fail2ban

7. Take a snapshot

In your Hostn.ME dashboard click Snapshots → Create. You now have a clean, secure baseline to restore any time.

Next: Host Multiple Sites with Nginx.

Stuck on a step?

Our AI assistant knows every tutorial, and a real engineer is one click away.