在 CentOS 上,您可以通过查看 /var/log/secure 文件来检查 SSH 登录日志。要查看此文件,您可以使用 cat、less 或 grep 等命令。以下是一些示例:
cat 命令查看整个日志文件:sudo cat /var/log/secure
less 命令分页查看日志文件:sudo less /var/log/secure
在 less 查看器中,您可以使用上下箭头或 PgUp/PgDn 键来浏览日志。按 q 退出查看器。
grep 命令搜索特定的关键字,例如查找所有成功的 SSH 登录:sudo grep 'sshd.*Accepted' /var/log/secure
或者查找所有失败的 SSH 登录:
sudo grep 'sshd.*Failed' /var/log/secure
您还可以结合 grep 和其他命令来获取更详细的信息,例如查找特定 IP 地址的登录尝试:
sudo grep 'sshd.*192.168.1.1' /var/log/secure
请注意,您可能需要使用 sudo 命令来获取管理员权限,以便查看 /var/log/secure 文件。