首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对于不存在的用户,我如何隐藏失败的ssh尝试?

对于不存在的用户,我如何隐藏失败的ssh尝试?
EN

Unix & Linux用户
提问于 2019-12-10 04:04:06
回答 1查看 1.4K关注 0票数 3

问题

如何排除不重要的、失败的SSH登录?

背景

对于环境感知,我喜欢在我管理的每个GNU/Linux框上都有显示系统错误日志的小背景窗口。我以前用xconsole来做这件事,但是现在使用了运行journalctl -f的xterm。

不幸的是,在ssh是所需服务的机器上,日志日志是来自试图使用通用名称/密码列表的破解者的源源不断的杂乱。我看到,每秒钟都会出现故障,甚至连根本不存在的帐户都不存在。这使得在我的控制台日志中很难看到任何其他内容。

解决方案?

我不知道系统的一半,所以有可能有一个巧妙的,简单的答案,但我还没有找到一个。任何解决方案都是受欢迎的。我怀疑这将需要使用pam、journalctl和/或grep -v

我正在寻找一个解决方案,仍然显示我试图对现有帐户。但是,如果这太困难了,我将接受一个隐藏所有失败的登录尝试的答案。

期刊实例

不要显示以下内容:

代码语言:javascript
复制
Dec 12 17:19:21 gaia sshd[10146]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=139.59.90.40  user=root
Dec 12 17:19:21 gaia sshd[10148]: Invalid user git from 14.29.201.30
Dec 12 17:19:21 gaia sshd[10148]: input_userauth_request: invalid user git [preauth]
Dec 12 17:19:21 gaia sshd[10148]: pam_unix(sshd:auth): check pass; user unknown
Dec 12 17:19:21 gaia sshd[10148]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=14.29.201.30
Dec 12 17:19:22 gaia sshd[10150]: Invalid user molisoft from 5.135.152.97
Dec 12 17:19:22 gaia sshd[10150]: input_userauth_request: invalid user molisoft [preauth]
Dec 12 17:19:22 gaia sshd[10150]: pam_unix(sshd:auth): check pass; user unknown
Dec 12 17:19:22 gaia sshd[10150]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=5.135.152.97
Dec 12 17:19:23 gaia sshd[10146]: Failed password for root from 139.59.90.40 port 37752 ssh2
Dec 12 17:19:23 gaia sshd[10146]: Received disconnect from 139.59.90.40: 11: Bye Bye [preauth]
Dec 12 17:19:23 gaia sshd[10148]: Failed password for invalid user git from 14.29.201.30 port 41178 ssh2
Dec 12 17:19:23 gaia sshd[10148]: Received disconnect from 14.29.201.30: 11: Bye Bye [preauth]
Dec 12 17:19:24 gaia sshd[10150]: Failed password for invalid user molisoft from 5.135.152.97 port 50730 ssh2
Dec 12 17:19:24 gaia sshd[10150]: Received disconnect from 5.135.152.97: 11: Bye Bye [preauth]

但是要显示有效的登录:

代码语言:javascript
复制
Dec 10 08:56:16 gaia sshd[1414]: Accepted publickey for sophia from 24.22.130.192 port 41610 ssh2: RSA 6b:5f:aa:9c:d8:33:65:2c:c4:0c:88:12:ec:9b:ff:51
Dec 10 08:56:16 gaia sshd[1414]: pam_unix(sshd:session): session opened for user sophia by (uid=0)
Dec 10 21:06:37 gaia sshd[1414]: pam_unix(sshd:session): session closed for user sophia

还显示对有效帐户(根除外)的尝试失败:

代码语言:javascript
复制
Dec 12 00:46:28 gaia sshd[30924]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.9.134  user=sophia
Dec 12 00:46:30 gaia sshd[30924]: Failed password for sophia from 192.168.9.134 port 55888 ssh2
Dec 12 00:46:33 gaia sshd[30924]: Connection closed by authenticating user sophia 192.168.9.134 port 55888 [preauth]

当然,任何不是sshd的服务都应该显示出来。

代码语言:javascript
复制
Dec 10 08:56:16 gaia systemd[1]: Started User Manager for UID 3237.

定义为“用户名不存在”或“用户名是根”。根ssh在我的boxen上是禁用的。

我确实使用fail2ban。这是有帮助的,但尝试来自太多的IP地址。

例如,日志允许grep,但不允许grep -v排除某些标准。

EN

回答 1

Unix & Linux用户

发布于 2020-10-16 01:52:38

您可以通过以下方法显著减少/etc/ssh/sshd_config中的日志垃圾邮件:

  • 禁用密码身份验证并只允许公开密钥: PasswordAuthentication,no ChallengeResponseAuthentication,no PermitRootLogin禁忌-密码
  • 使用INFO或更低级别(INFO是sshd上游默认值):LogLevel信息

只有当登录垃圾邮件机器人不使用您的密钥交换方法时,才能摆脱这种情况,例如:

代码语言:javascript
复制
Unable to negotiate with 203.0.113.1 port 40442: no matching key exchange method found. Their offer: diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1 [preauth]

我还没找到办法摆脱这点。

票数 0
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/556455

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档