Identify top IPs generating failed SSH login attempts from auth log
Identify top IPs generating failed SSH login attempts from auth log
Linux CLI / Log Analysis
Command
grep "Failed password" /var/log/auth.log | awk '{print $11}' | sort | uniq -c | sort -rn | head -20
Syntax
grep "Failed password" /var/log/auth.log | awk ... | sort | uniq -c
Use case
Daily security review or incident response when detecting potential SSH brute-force campaigns against internet-facing Linux servers.
Explanation
SSH brute-force detection pipeline: • grep "Failed password" → Filter failed auth events • awk \'{print \$11}\' → Extract source IP from log line • sort | uniq -c → Count occurrences per IP • sort -rn → Sort numerically in reverse (highest first) • head -20 → Show top 20 offenders Use these IPs to create firewall block rules or threat intel feeds. Combine with fail2ban for automated blocking.
Example output
1523 192.168.1.200
847 10.0.0.45
612 203.0.113.88
445 198.51.100.1
89 172.16.0.50
More examples
Primary example
grep "Failed password" /var/log/auth.log | awk '{print $11}' | sort | uniq -c | sort -rn | head -20
Daily security review or incident response when detecting potential SSH brute-force campaigns against internet-facing Linux servers.
Related
Real-time SSH authentication event monitoring from systemd journal
Real-time SSH authentication event monitoring from systemd journal
journalctl -u ssh.service --since "1 hour ago" --no-pager | grep -E "(Accepted|Failed|Invalid)" | awk '{print $1, $2, $3, $9, $11}'