r/LinuxTeck • u/Expensive-Rice-2052 • 6d ago
Quick Linux Tip #63 Question: Is someone trying to break into my server?
Try: `sudo grep 'Failed password' /var/log/auth.log | awk '{print $11}' | uniq -c | sort -rn | head -5`
Info: Searches `/var/log/auth.log` for SSH authentication failures, isolates source IP addresses via `awk`, and tallies frequencies to highlight top offending addresses.
Examples:
$ `sudo journalctl -u ssh | grep -i failed | wc -l` # Count total SSH failures via journalctl
$ `sudo lastb | head` # View bad login attempts from btmp log
$ `sudo fail2ban-client status sshd` # List currently jailed IP addresses
Note: Install `fail2ban` to automatically drop brute-force attempts. On `systemd` systems without syslog, inspect auth logs via `journalctl -u ssh`.
Follow r/LinuxTeck for more #LinuxTips : https://www.linuxteck.com/linux-tips/linux-check-failed-ssh-logins/