Secure an Ubuntu VPS in 15 Minutes with Docker

Resumen

Pixel shares a 15-minute checklist for securing a fresh Ubuntu 24.04 VPS before deploying apps. It covers creating a non-root user, hardening SSH, configuring UFW, and installing Fail2ban to reduce brute-force risks and avoid exposing Docker services unnecessarily.

DEV Community

Production VPS Setup in 15 Minutes: Docker + UFW + Fail2ban + Auto-Updates

I once spun up a new VPS, installed Docker, deployed an app, and forgot the firewall. Two days later the logs were full of SSH brute-force attempts. Lesson learned: default VPS is not secure. Docker also exposes ports to the world by default. This article is the checklist I use every time I provision a fresh VPS. 15 minutes, done. Works for homelab, side projects, or small production. Prerequisites Fresh Ubuntu 24.04 LTS VPS (any provider) SSH key ready (no password login) Domain optional (for SSL later) Recommended: DigitalOcean — $200 credit for new accounts Step 1: User & SSH Hardening Login as root, create a non-root user: adduser deploy
usermod -aG sudo deploy
Copy SSH key to the new user: mkdir -p /home/deploy/.ssh
cp /root/.ssh/authorized_keys /home/deploy/.ssh/
chown -R deploy:deploy /home/deploy/.ssh
chmod 700 /home/deploy/.ssh
chmod 600 /home/deploy/.ssh/authorized_keys
Test login as deploy in a new terminal. If it works, harden SSH: nano /etc/ssh/sshd_config
Change/uncomment these lines: PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
Restart SSH: systemctl reload sshd
Step 2: UFW Firewall Default deny incoming, allow outgoing. Only open what you need: ufw default deny incoming
ufw default allow outgoing

SSH (port 22) - change if using custom port

ufw allow 22/tcp

HTTP/HTTPS for web

ufw allow 80/tcp
ufw allow 443/tcp

Docker internal (optional, if containers need to talk)

ufw allow from 172.17.0.0/16

Enable

ufw enable
Verify: ufw status verbose
Step 3: Fail2ban Block IPs that repeatedly fail login. Install: apt update && apt install -y fail2ban
Create custom config: nano /etc/fail2ban/jail.local
Content: [DEFAULT]
bantime = 3600
findtime = 600
maxretry = 3
backend = systemd

[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 3

[docker-auth]
enabled = true
port = 2375,2376
filter = docker-auth
logpath = /var/log/auth.log
maxretry = 3
Restart: systemctl enable --now fail2ban
fail2ban-client status sshd
Step 4: Docker + Docker Compose Install from official repo (not apt default which can be outdated): # Remove old versions
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do
apt remove -y $pkg
done

Install dependencies

apt update && apt install -y ca-certificates curl gnupg lsb-release

Add Docker GPG key

install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg

Add repository

echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null

Install

apt update && apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Add user to docker group: usermod -aG docker deploy
Test (logout/login first, or newgrp docker): docker run --rm hello-world
Step 5: Automatic Security Updates Production servers need patches without manual intervention: apt install -y unattended-upgrades needrestart
Configure: nano /etc/apt/apt.conf.d/50unattended-upgrades
Ensure these are uncommented: Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}-security";
"${distro_id}:${distro_codename}-updates";
};
Unattended-Upgrade::AutoFixInterruptedDpkg "true";
Unattended-Upgrade::MinimalSteps "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
Unattended-Upgrade::Automatic-Reboot "false";
Enable timer: systemctl enable --now unattended-upgrades
Check logs: tail -f /var/log/unattended-upgrades/unattended-upgrades.log
Step 6: Verification & Test Post-setup checklist: # 1. SSH key-only
ssh -o PasswordAuthentication=no deploy@

2. Firewall active

ufw status

3. Fail2ban running...

Secure an Ubuntu VPS in 15 Minutes with Docker
Powered by Readybot.io

Lo último de Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …