Patch the server
Install available security and package updates before adding application software.
sudo apt update && sudo apt upgrade -yCreate an operator account
Use a named sudo account instead of operating as root.
sudo adduser <operator>
sudo usermod -aG sudo <operator>Install the SSH public key
Copy only your public key to the new account, then confirm login from a second terminal.
ssh-copy-id <operator>@<server-ip>ssh <operator>@<server-ip>Important: Keep the current root session open until the new SSH login works.
Configure the firewall
Allow SSH before enabling UFW. Add HTTP and HTTPS when this host will serve web traffic.
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw status verboseHarden SSH
After key login is verified, disable direct root login and password authentication in an SSH config drop-in.
sudoedit /etc/ssh/sshd_config.d/99-hardening.confsudo sshd -t && sudo systemctl reload sshNote: Set PermitRootLogin no and PasswordAuthentication no. Validate with sshd -t before reload.
Enable automated protection
Install unattended security updates and Fail2ban, then confirm both services.
sudo apt install -y unattended-upgrades fail2ban
sudo dpkg-reconfigure -plow unattended-upgrades
sudo systemctl enable --now fail2banFinal verification
- ✓ A second terminal can sign in with the operator SSH key
- ✓ sudo ufw status shows only required inbound ports
- ✓ sudo sshd -t exits successfully
- ✓ systemctl is-active fail2ban returns active