Back to library
Defensive Beginner Free

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

Log in to save

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.

linux log-analysis ssh brute-force auth detection

Related

Defensive Intermediate Free

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}'
journalctl systemd ssh log-analysis monitoring
Linux CLI / Log Analysis Open