在 CentOS 系统中,SSH 日志文件通常位于 /var/log/secure
。要查看和分析 SSH 日志,你可以使用以下命令:
sudo cat /var/log/secure | grep sshd
sudo grep 'sshd' /var/log/secure --since "2021-09-01 00:00:00" --until "2021-09-30 23:59:59"
将日期和时间替换为你感兴趣的时间段。
sudo grep 'Failed password' /var/log/secure
sudo grep 'Accepted password' /var/log/secure
sudo grep 'sshd' /var/log/secure | awk '{print $11}' | cut -d':' -f1 | sort | uniq -c | sort -nr
sudo grep 'sshd' /var/log/secure | awk '{print $1}' | sort | uniq -c | sort -nr
这些命令可以帮助你查看和分析 SSH 日志。你可以根据需要修改它们以满足你的需求。在分析日志时,请注意异常行为,例如多次失败的登录尝试、来自未知 IP 地址的登录尝试等。这些可能是潜在的安全威胁,需要进一步调查和处理。