Skip to content

Instantly share code, notes, and snippets.

@pbalduino
Created January 24, 2011 18:03
Show Gist options
  • Save pbalduino/793621 to your computer and use it in GitHub Desktop.
Save pbalduino/793621 to your computer and use it in GitHub Desktop.
Script to autoblock break attempts via SSH with UFW
#!/bin/sh
USER=johndoe
echo "[Running: $(date)]" >> /var/log/autoblock.log
grep -a -E -e 'Failed password for' /var/log/auth.log | awk '$9 != "$USER" && $9 != "invalid" {print "ufw deny from "$11}' | sh | grep -vi "skipping" >> /var/log/autoblock.log
grep -a -E -e 'Failed password for invalid' /var/log/auth.log | awk '$11 != "$USER" {print "ufw deny from "$13}' | sh | grep -vi "skipping" >> /var/log/autoblock.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment