Skip to content

Instantly share code, notes, and snippets.

@user454322
Created July 25, 2013 02:38
Show Gist options
  • Save user454322/6076479 to your computer and use it in GitHub Desktop.
Save user454322/6076479 to your computer and use it in GitHub Desktop.
iptables chain to restrict SSH login attempts
#!/bin/sh
#-- Creates a SSH-fal chain
/sbin/iptables -N SSH-fal
#-- Only 3 login attempts can be done from the same IP whithin a minute
/sbin/iptables -A SSH-fal -p tcp --dport 22 -m state --state NEW -m recent --set --name SSH
/sbin/iptables -A SSH-fal -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 2 --rttl --name SSH -j LOG --log-prefix "IPTABLES: failed login attempt"
/sbin/iptables -A SSH-fal -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 60 --hitcount 3 --rttl --name SSH -j DROP
#-- Load rules definided in SSH-fal
/sbin/iptables -A INPUT -j SSH-fal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment