There were xxx failed login attempts since the last successful login

创建日期:2024-06-21
更新日期:2024-12-05

当您通过shell登录到Linux(Ubuntu/CentOS/Redhat)时,可能会收到警告。

Last failed login: Fri Feb 23 08:09:01 CST 2024 from gutehomepage.de on ssh:notty
There were 196 failed login attempts since the last successful login.
Last login: Thu Feb 22 10:58:05 2024 from 27.195.172.242

解决方法

1、查看登录失败的IP地址。

grep "Failed password for invalid user" /var/log/secure | awk '{print $13}' | sort | uniq -c | sort -nr

得到

67083 172.232.61.112
8367 172.104.154.78
8332 164.92.165.198
201 61.164.170.242
199 185.98.83.220
193 122.176.52.13
192 106.14.61.79
191 139.59.128.14

2、将失败次数最多的IP加入hosts.allow文件即可。

cd /etc
cp hosts.allow hosts.allow.bak
vim hosts.allow

在最下面加入以下内容即可。

sshd:172.232.61.112:deny
sshd:172.104.154.78:deny
sshd:164.92.165.198:deny

简介

一个来自三线小城市的程序员开发经验总结。