Ssh – Firewalls (ufw vs apf) on Ubuntu

fail2banfirewalllampSecurityssh

On my LAMP servers, do either of the firewall interfaces (ufw or apt) allow you to setup rate limiting to automatically ban brute force attempts (e.g. via SSH)? Or, is it best to install fail2ban in conjunction with strict firewall rules?

Best Answer

For ufw look into the limit command.

sudo ufw limit ssh

From the ufw man page section on the limit command:

RULE SYNTAX
   [...]

   ufw supports connection rate limiting, which is useful  for  protecting
   against  brute-force  login attacks. ufw will deny connections if an IP
   address has attempted to initiate 6 or more connections in the last  30
   seconds.    See  http://www.debian-administration.org/articles/187  for
   details.  Typical usage is:

     ufw limit ssh/tcp