Hardening Your Production Cloud VPS
Exposing an unhardened server to the public internet attracts automated botnets within minutes. This step-by-step security blueprint hardens your Ubuntu/Debian server against unauthorized access and volumetric brute-force assaults.
1. Update System Packages
sudo apt update && sudo apt upgrade -y
2. Create a Non-Root Sudo User
# Create user and assign sudo privileges
sudo adduser zozo_admin
sudo usermod -aG sudo zozo_admin
# Copy authorized SSH keys from root to new user
sudo mkdir -p /home/zozo_admin/.ssh
sudo cp ~/.ssh/authorized_keys /home/zozo_admin/.ssh/
sudo chown -R zozo_admin:zozo_admin /home/zozo_admin/.ssh
sudo chmod 700 /home/zozo_admin/.ssh
sudo chmod 600 /home/zozo_admin/.ssh/authorized_keys
3. Configure UFW (Uncomplicated Firewall)
# Set default policies: block incoming, allow outgoing
sudo ufw default deny incoming
sudo ufw default allow outgoing
# Allow essential web and administration ports
sudo ufw allow 22/tcp comment 'SSH'
sudo ufw allow 80/tcp comment 'HTTP'
sudo ufw allow 443/tcp comment 'HTTPS'
# Enable firewall
sudo ufw enable
sudo ufw status verbose
4. Install and Configure Fail2ban
Fail2ban dynamically monitors auth logs and bans malicious IP addresses after repeated failed login attempts via iptables:
sudo apt install fail2ban -y
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
5. Disable SSH Root Password Login
Edit /etc/ssh/sshd_config and update the following directives:
PermitRootLogin prohibit-password
PasswordAuthentication no
PubkeyAuthentication yes
Restart the SSH daemon: sudo systemctl restart sshd.