Hundreds of failed ssh logins

You can use iptables to rate-limit new incoming connections to the SSH port. I’d have to see your entire iptables configuration in order to give you a turnkey solution, but you’re basically talking about adding rules like:

iptables -A INPUT -p tcp --dport 22 -m recent --update --seconds 60 --hitcount 5 --name SSH --rsource -j DROP 
iptables -A INPUT -p tcp --dport 22 -m recent --set --name SSH --rsource -j ACCEPT 

These rules assume that you’re accepting ESTABLISHED connections earlier in the table (so that only new connections will hit these rules). New SSH connections will hit these rules and be marked. In 60 seconds, 5 attempts from a single IP address will result in new incoming connections from that IP being dropped.

This has worked well for me.

Edit: I prefer this method to “fail2ban” because no additional software to be installed, and happens totally in kernel-mode. It doesn’t handle parsing log files like “fail2ban” will, but if your problem is only with SSH I wouldn’t use something user-mode that requires software installation and is more complex.

Leave a Comment