Hardening SSH access on Linux servers Print

  • 0

Every internet-facing server gets thousands of SSH login attempts a day. These settings make them harmless.

In /etc/ssh/sshd_config

PermitRootLogin prohibit-password   # or "no" if you use sudo users
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
AllowUsers alice bob rakar

Make sure your key login works in a second session before you reload: sshd -t && systemctl reload sshd. Keep the first session open until you've tested.

Also

  • Use Ed25519 keys: ssh-keygen -t ed25519.
  • Allow port 22 only from your office, VPN or bastion IPs in the firewall, where possible.
  • Use a bastion host with MFA for teams.
  • Add fail2ban or CrowdSec to block repeated failures (see Blocking brute-force attacks with fail2ban or CrowdSec).
  • Changing the SSH port reduces log noise but is not security on its own.
  • Remove keys of people who have left. Review ~/.ssh/authorized_keys on every server regularly.

Was this answer helpful?

« Back