SSH protection (fail2ban): blocked after wrong passwords Print

  • 0

Every DP HOST VPS running Ubuntu or Debian comes with fail2ban turned on, also after you reinstall the operating system with a password. It protects SSH access against bots that try to guess the password.

  • The rule: anyone who gets the password wrong 5 times within 10 minutes is blocked for 1 hour. Getting the SSH password wrong blocks port 22 (SSH) only. If you chose Cockpit with your order, its panel has the same rule, kept separate: getting the Cockpit password wrong blocks port 9090 only. Your website and apps keep working normally.
  • I got blocked (SSH started refusing the connection after I mistyped the password): wait 1 hour, or log in through the VNC console in the client area (on the service page), which does not use SSH, and run fail2ban-client set sshd unbanip YOUR_IP. To unblock the Cockpit panel (port 9090), run from the same console: fail2ban-client set dphost-cockpit unbanip YOUR_IP.
  • See who is blocked: fail2ban-client status sshd (the Banned IP list line).
  • Always allow your IP (if it is fixed): create the file /etc/fail2ban/jail.d/zz-local.local with the 2 lines below, replacing YOUR_IP with your address, and run systemctl restart fail2ban:
    [sshd]
    ignoreip = %(known/ignoreip)s YOUR_IP
    The %(known/ignoreip)s part keeps the addresses that are already allowed. Do not replace the whole list and do not put this line in the [DEFAULT] section. For Cockpit, repeat the 2 lines with the [dphost-cockpit] section.
  • Change the rules: in the same zz-local.local file, in the [sshd] section. For example, for 10 attempts and a 1-day block:
    [sshd]
    maxretry = 10
    bantime = 1d
    If the file already has an [sshd] section, add the lines to it. Then run systemctl restart fail2ban. Do not edit /etc/fail2ban/jail.d/dphost.local: it belongs to DP HOST and may be rewritten by the automatic adjustments.
  • Changed the SSH port? Add port = NEW_PORT to the [sshd] section of zz-local.local and restart fail2ban. Otherwise the block keeps covering port 22 only.
  • Turn it off (not recommended): systemctl disable --now fail2ban
  • Allowed address: the DP HOST file allows the address of our automatic adjustments, which run after installation and after a reinstall. Do not remove it: without it, the automatic reinstall may fail.
  • Reinstalling: reinstalling with a password brings the protection back automatically. Reinstalling with an SSH key only does not install it automatically: open a ticket and we will install it.
  • AlmaLinux and Rocky Linux: the automatic protection covers Ubuntu and Debian only; on these systems fail2ban is not installed. If you want to use it, installing it is up to you.
  • Windows VPS: not applicable.

Was this answer helpful?

« Back

Powered by WHMCompleteSolution