ssh 一分钟被打 1000 次, fail2ban 有用吗?

2022-04-22 08:03:32 +08:00
 elboble
Apr 20 23:40:03 debian99 sshd[2443]: Failed password for invalid user liyanjun from 134.209.229.252 port 44720 ssh2
Apr 20 23:40:03 debian99 sshd[2450]: Failed password for invalid user liyaocheng from 134.209.229.252 port 44948 ssh2
Apr 20 23:40:03 debian99 sshd[2453]: Failed password for invalid user liyifei from 134.209.229.252 port 45180 ssh2
Apr 20 23:40:03 debian99 sshd[2431]: Failed password for invalid user lixy from 134.209.229.252 port 43946 ssh2
Apr 20 23:40:03 debian99 sshd[2415]: Failed password for invalid user lixiang from 134.209.229.252 port 43168 ssh2
Apr 20 23:40:03 debian99 sshd[2459]: Failed password for invalid user liyongmin from 134.209.229.252 port 45918 ssh2
Apr 20 23:40:03 debian99 sshd[2441]: Failed password for invalid user liyanhao from 134.209.229.252 port 44636 ssh2
Apr 20 23:40:03 debian99 sshd[2446]: Failed password for invalid user liyanjun from 134.209.229.252 port 44794 ssh2
@:~$ sudo cat /var/log/auth.log | grep 134.209.229.252 | grep invalid | wc -l
948
@:~$ 

暂时没用 fail2ban ,自己写个脚本,每一分钟扫一次 auth.log,大于 10 次就 ban ,但是有的 ip 一分钟就能尝试 1000 次,太凶残了,能限制 ssh 并发个数吗,超过 10 个,就不要管了。

9029 次点击
所在节点    Linux
65 条回复
m4d3bug
2022-04-22 09:25:49 +08:00
开个 cockpit 用算了,sshd 都不开
duzhor
2022-04-22 09:32:40 +08:00
修改以下设置减少 99%攻击

```
生成密钥
ssh-keygen -t rsa -f ~/.ssh/id_rsa -N '' -q
```

把密钥保存到本地

```
#/etc/ssh/sshd_config
Port 23456 #修改 SSH 端口
PermitRootLogin prohibit-password #root 禁止密码和交互登录
PasswordAuthentication no #禁止密码登录
```

修改前记得开启防火墙端口. 重启 ssh 服务
des
2022-04-22 09:47:54 +08:00
你可能搜索的是 端口敲门
makelove
2022-04-22 09:50:21 +08:00
从来不折腾这种,只要起个合理长度的密码或禁密码就可以了
webshe11
2022-04-22 09:50:51 +08:00
@elboble #9 我记得 Fail2ban 用的是 inotify 吧?
Mark24
2022-04-22 10:12:47 +08:00
上周好像有个新闻。美国对中国网络发起攻击。提权了就会当肉鸡攻击俄罗斯、白俄罗斯。
lolizeppelin
2022-04-22 10:17:44 +08:00
端口改了没....?
没改端口的话,改个端口能屏蔽 95%
iqoo
2022-04-22 10:21:03 +08:00
ssh 用高位端口,加上 iptables 防端口扫描就可以

https://github.com/EtherDream/anti-portscan
3dwelcome
2022-04-22 10:27:17 +08:00
@iqoo 我还在想,端口怎么防扫描,原来是下陷阱,真有创意。
FullBridgeRect
2022-04-22 11:05:35 +08:00
@elboble 如果对自己的用户名密码有自信,f2b 也够用了,即使再凶残被探测到了就 ban 了,就 1 分钟的事
justrand
2022-04-22 11:32:45 +08:00
关闭密码登录就不管了,我刚才去看了下每天 10w 条扫描日志,不管他就行了。
davidyin
2022-04-22 11:37:31 +08:00
指定允许登录的 IP ,白名单。
yujinchn
2022-04-22 12:32:31 +08:00
可以设置连续超过多少次就 ban 掉 ip 的吧
yujinchn
2022-04-22 12:33:10 +08:00
就用 fail2ban 限制,很快的
huangzxx
2022-04-22 12:34:43 +08:00
正确姿势:换端口,只允许密钥登录
iBugOne
2022-04-22 12:53:24 +08:00
fail2ban 没有性能问题,只要你姿势正确。它扫描日志有个 inotify ( pyinotify )后端,可以随日志变化来增量扫描,就像 tail -f 一样
dengshen
2022-04-22 13:01:20 +08:00
禁用密码登陆+证书登陆+改 sshd 端口
woshinide300yuan
2022-04-22 13:05:52 +08:00
我都是用安全组里的限制 IP 访问 22 端口,不知道有用没。反正我不写自己的 IP ,我打不开 SSH 都!~
hgc81538
2022-04-22 13:51:59 +08:00
改成很長+複雜密碼
例如: ZZ&7A:Y_J@Te2]mM2I#Fy@U?N8jmg~`q|0!M%Zi-|e-8vsD?|9l]llg2!6~q6zkb
tiny1994
2022-04-22 13:55:00 +08:00
可以试试新出来的工具~
CrowdSec
<amp-youtube data-videoid="2OEDFCo1VXY" layout="responsive" width="480" height="270"></amp-youtube>

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/848484

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX