Knowledgebase

How to secure your Linux server

A new server is scanned by bots within minutes. These steps block most attacks:

  1. Use SSH keys. Create a key pair (ssh-keygen), copy the public key to ~/.ssh/authorized_keys, then set PasswordAuthentication no in /etc/ssh/sshd_config and restart SSH. Test a second session before closing the first one.
  2. Disable direct root login (PermitRootLogin no) after creating a sudo user.
  3. Enable a firewall. Ubuntu: ufw allow OpenSSH && ufw enable. AlmaLinux: firewall-cmd --permanent --add-service=ssh then --reload. Open only the ports your services use (80, 443, ...).
  4. Install fail2ban to block repeated login attempts.
  5. Keep everything updated and enable automatic security updates where suitable.
  6. Take regular backups and test restoring them.

Changing the default SSH port reduces noise in the logs but is not a replacement for keys and a firewall.

Was this answer helpful?

0 Users Found This Useful