查看用户登录日志的方法取决于操作系统和日志管理工具。下面按常见场景给你一份速查指南。
last
/var/log/wtmp只看某个用户:
last username
lastb
/var/log/btmpwho
w
who:当前登录用户w:更详细(IP、正在执行的命令)journalctl -u sshd
查看 SSH 登录日志:
journalctl -u sshd | grep "Accepted"
查看失败登录:
journalctl -u sshd | grep "Failed"
/var/log/secure # CentOS / RHEL
/var/log/auth.log # Ubuntu / Debian
示例:
grep "Accepted" /var/log/secure
grep "Failed" /var/log/secure
Windows 日志 → 安全
Get-WinEvent -FilterHashtable @{LogName='Security'; ID=4624}
查看失败登录:
Get-WinEvent -FilterHashtable @{LogName='Security'; ID=4625}
| 系统 | 文件 / 命令 |
|---|---|
| Linux | last, lastb, who, w |
| Linux | /var/log/secure, /var/log/auth.log |
| Linux | journalctl -u sshd |
| Windows | 事件查看器 → 安全 |
| Windows | PowerShell Get-WinEvent |
last | head
lastb | head
grep "Accepted.*192.168.1.100" /var/log/secure
如果你能告诉我:
我可以给你更精确的命令或脚本。