Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Ban all IPs that attempted to access to ssh without success

Tags: grep print sort

grep sshd /var/log/auth.log  | \
grep -Eo 'rhost=([1-2]?[0-9]{0,2}\.){3,3}[1-2]?[0-9]{0,2}' | \
awk -F"=" '{print $2}' | sort | uniq -c |sort -k2nr | \
awk '$1>3 {print $2}' |\
xargs -I% sudo iptables -A INPUT -s % -j DROP






This post first appeared on Linux Command's, please read the originial post: here

Share the post

Ban all IPs that attempted to access to ssh without success

×

Subscribe to Linux Command's

Get updates delivered right to your inbox!

Thank you for your subscription

×