Steps for securing a fresh SSH server:

  • Disable root login
    • sudo vim /etc/ssh/sshd_config
    • Uncomment “PermitRootLogin no”
    • Restart ssh: sudo systemctl restart sshd
  • Disable password login
  • Keyfile login (generate key if necessary, use ssh-copy-id to copy public key to authorized hosts)
  • Change SSH port
    • Edit sshd_config
    • Update “Port 22” line (uncomment if necessary) to the port you want to use
  • Install fail2ban