Prerequisites
Before checking failed login attempts, make sure you have:
- SSH access to your VPS
- Root or sudo privileges
⚠️ Multiple failed login attempts from the same IP indicate a brute force attack.
Method 1: Using lastb Command (Quick View)
Connect to your VPS:
ssh hxroot@YOUR_SERVER_IP -p 22View last 10 failed attempts:
lastb -10Example output:
root ssh:notty 185.45.6.78 Mon Apr 28 05:23:15 2026 - 05:23:15 (00:00)
admin ssh:notty 185.45.6.78 Mon Apr 28 05:23:12 2026 - 05:23:12 (00:00)
user ssh:notty 203.0.113.45 Mon Apr 28 05:23:09 2026 - 05:23:09 (00:00)Method 2: Count Failed Attempts by IP
lastb | awk '{print $3}' | sort | uniq -c | sort -rn | head -10Output shows IP addresses with most failed attempts:
245 185.45.6.78
89 203.0.113.45
12 198.51.100.23Method 3: Count Failed Attempts by Username
lastb | awk '{print $1}' | sort | uniq -c | sort -rn | head -10Shows which usernames attackers are trying:
156 root
78 admin
45 user
32 testMethod 4: Check SSH Logs Directly
Ubuntu/Debian:
grep "Failed password" /var/log/auth.log | tail -20CentOS/RHEL:
grep "Failed password" /var/log/secure | tail -20Show with timestamps and IPs:
grep "Failed password" /var/log/auth.log | awk '{print $1,$2,$3,$9,$11}' | tail -20Method 5: Failed Attempts in Last Hour
grep "$(date --date='1 hour ago' +'%b %e %H')" /var/log/auth.log | grep "Failed password" | wc -lMethod 6: Monitor Failed Attempts in Real Time
tail -f /var/log/auth.log | grep "Failed password"Press Ctrl+C to stop.
Method 7: Check for Invalid User Attempts
grep "Invalid user" /var/log/auth.log | tail -20Method 8: Visualize Failed Attempts Over Time
#!/bin/bash
for hour in {0..23}; do
COUNT=$(grep "$(date +'%b %e') $hour:" /var/log/auth.log | grep "Failed password" | wc -l)
echo "$hour:00 - $(printf '%3d' $COUNT) attempts"
doneSet Up Failed Login Alert
Create monitoring script:
#!/bin/bash
THRESHOLD=10
FAILED_COUNT=$(grep "$(date +'%b %e')" /var/log/auth.log | grep "Failed password" | wc -l)
if [ $FAILED_COUNT -gt $THRESHOLD ]; then
echo "Warning: $FAILED_COUNT failed login attempts detected today on $(hostname)" | mail -s "SSH Attack Alert" admin@example.com
fiAdd to cron:
0 * * * * /root/check_failed_logins.shCommon Attack Patterns
- Brute force on root account
- Attempting common usernames (admin, user, test, ubuntu)
- Dictionary attacks with thousands of passwords
- Slow attacks (trying once every few minutes to avoid detection)
Protect Against Failed Login Attempts
Install Fail2ban:
apt install fail2ban -yChange SSH port from default 22:
nano /etc/ssh/sshd_configPort 2222systemctl restart sshdDisable root login:
PermitRootLogin noUse SSH keys only:
PasswordAuthentication noExport Failed Login Data for Analysis
lastb > failed_logins_$(date +%Y%m%d).txtgrep "Failed password" /var/log/auth.log > failed_attempts.log✅ You can now monitor failed login attempts and take action to secure your Hostxpeed VPS.