Security hardening
A practical checklist to lock down a new Linux VPS — SSH keys, no root login, fail2ban and updates.
1 min read
On this page
Internet-facing servers are scanned constantly. This checklist blocks the vast majority of automated attacks.
1. Update and auto-update#
bash
sudo apt update && sudo apt full-upgrade -y
sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades2. Key-only SSH, no root login#
First confirm key login works for your sudo user (Root access). Then create /etc/ssh/sshd_config.d/99-hardening.conf:
text
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yesTest the config and reload:
bash
sudo sshd -t && sudo systemctl reload ssh3. Firewall#
Allow only what you need — see Firewall configuration.
4. Fail2ban#
Bans IPs that repeatedly fail logins:
bash
sudo apt install -y fail2ban
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd5. Least privilege for apps#
- Run services as dedicated users, not root.
- Keep secrets in files readable only by the service (
chmod 600). - Don't expose databases publicly; bind them to
127.0.0.1.
6. Know what's listening#
bash
sudo ss -tulpnAnything listening on 0.0.0.0 or [::] is reachable from the internet unless the firewall blocks it.
7. Backups#
Hardening reduces risk; backups are what save you. See Creating backups.
Was this page helpful?
