Essential Linux Server Hardening: The First 10 Minutes Setup Guide

Whenever you spin up a fresh virtual machine or cloud instance (Ubuntu/Debian), securing your server before exposing it to public network traffic is essential. Follow these foundational hardening steps.

Step 1: Create a Non-Root Sudo User

Running everyday administrative operations directly as the root user poses unnecessary risk. Create a dedicated administrative user:

bash - user setup
# Add new user (replace 'adminuser' with your desired username)
adduser adminuser

# Grant administrative privileges
usermod -aG sudo adminuser

Step 2: Enforce SSH Key Authentication & Disable Root Login

Brute-force attacks target port 22 continuously. Disable remote root login and password-based SSH access:

bash - ssh configuration
# Open SSH daemon configuration
sudo nano /etc/ssh/sshd_config

# Set or update these key directives:
# PermitRootLogin no
# PasswordAuthentication no

# Validate configuration syntax and restart service
sudo sshd -t && sudo systemctl restart ssh

Step 3: Configure UFW (Uncomplicated Firewall)

Block all incoming ports by default and permit only essential traffic:

bash - firewall rules
# Set default policies
sudo ufw default deny incoming
sudo ufw default allow outgoing

# Allow SSH and web traffic
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

# Enable and inspect firewall status
sudo ufw enable
sudo ufw status verbose