DevOps #Devops #Linux #Security

Hardening your Linux server in 30 minutes

By CodeThere Super Admin

Practical steps to secure a fresh Linux VPS: SSH keys, fail2ban, UFW, automatic updates, and a few quick wins that most setups miss.

A fresh VPS is not secure by default. These steps take around 30 minutes and significantly reduce your attack surface.

1. SSH key authentication

Disable password login and root login via SSH:

PasswordAuthentication no
PermitRootLogin no
PubkeyAuthentication yes

Make sure your public key is in ~/.ssh/authorized_keys before reloading SSH.

2. Firewall with UFW

ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp   # or your custom SSH port
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable

3. Fail2ban

Install and enable fail2ban to block brute-force login attempts:

apt install -y fail2ban
systemctl enable fail2ban

4. Automatic security updates

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

5. Check open ports

Run ss -tlnp or netstat -tlnp and close anything you do not recognise. A standard web server should only listen on 22, 80, and 443 externally.

Related articles