Security help › Websites and servers
Lock down a new Linux server in 10 minutes
A step-by-step guide for Linux, with fixes for common problems.
Steps
- Update everything: sudo apt update && sudo apt upgrade -y (Red Hat family: sudo dnf upgrade -y).
- Make your own user and give it admin rights: sudo adduser yourname, then sudo usermod -aG sudo yourname.
- On your own computer, make a login key: ssh-keygen -t ed25519. Copy it to the server: ssh-copy-id yourname@your-server.
- Check you can log in with the key in a NEW window before changing anything else. Keep the old window open.
- Turn off password logins and root logins: in /etc/ssh/sshd_config set PasswordAuthentication no and PermitRootLogin no, then sudo systemctl restart ssh.
- Turn on the firewall, allowing SSH first: sudo ufw allow OpenSSH, then sudo ufw enable. Allow only the ports you use (e.g. sudo ufw allow 443/tcp for a website).
- Turn on automatic security updates: sudo apt install unattended-upgrades and sudo dpkg-reconfigure unattended-upgrades.
- Install the AegisTide watcher from the Servers page, so you hear about attacks and changes.
What you should see
You can still log in with your key in a new window; sudo ufw status says "Status: active"; the server shows Online in your dashboard.
Common problems
- I locked myself out Use your host's web console (Hetzner, OVH, DigitalOcean and others all have one), undo the last change in /etc/ssh/sshd_config, and restart ssh.
- "Permission denied (publickey)" The key isn't on the server for that user. Run ssh-copy-id again from your computer, or paste the .pub file into ~/.ssh/authorized_keys on the server.