我在我的 Linux 机器上收到以下错误消息。
sshd[9287]: message repeated 2 times: [ error: PAM: Authentication failure for root from 172.16.2.1]
sshd[9287]: Received disconnect from 172.16.2.1: 11: [preauth]
sshd[9312]: error: PAM: Authentication failure for root from 172.16.2.1
sshd[9315]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=172.16.2.1 user=root
Run Code Online (Sandbox Code Playgroud)
这种情况经常发生,我的日志中充满了此错误消息。如何克服这个问题?
有人试图暴力破解您的root用户密码。
\n(如果禁止密码登录也没关系\xe2\x80\x94他们仍然可以尝试,但每次都会失败。)
您通常不想抑制这些日志消息;当有人确实在某个时刻成功闯入您的系统时,它们可能是有用的信息。
\n (尽管在这种情况下您需要仅附加日志异地备份才能安全。)
您可以使用日志聚合系统(如Logstash或Graylog)将这些消息过滤到不同的视图中以单独处理它们,或者您可以grep -v '[Aa]uthentication failure]' /var/log/syslog | less在手动查看日志时将它们过滤掉。
您还可以向源系统的操作员报告暴力尝试,但这通常是针对风车的。
\n (请注意,您看到的是 NAT 网关的专用网络地址 (172.16.2.1),因此您需要检查网关的实际外部地址。)
通常的缓解措施只是预过滤和混淆:
\n\n确保root在您的:中禁用用户基于密码的登录/etc/ssh/sshd_config:
PermitRootLogin without-password\n\n# or\nPermitRootLogin no\n\n# or (at the very end of the file, since `Match` extends until the next `Match` or end of file)\nMatch User root\nPasswordAuthentication no\nRun Code Online (Sandbox Code Playgroud)