在 Debian 系统中,登录日志主要由 systemd 和 rsyslog 等组件记录。下面按常见场景给你一个完整查询方法。
journalctl(推荐,systemd 系统)Debian 8 及以后版本默认使用 systemd,登录日志由 systemd-logind 和 sshd 等记录。
journalctl _COMM=sshd
或
journalctl -u ssh
journalctl -u ssh | grep "Accepted"
journalctl -u ssh | grep "Failed"
journalctl --since "2025-01-01" --until "2025-01-20"
cat /var/log/auth.log
或实时查看:
tail -f /var/log/auth.log
grep "Accepted" /var/log/auth.log
grep "Failed" /var/log/auth.log
grep "session opened" /var/log/auth.log
last / lastb(最常用)last
只看某个用户:
last root
lastb
如果
lastb提示文件不存在,可能是日志未开启或已轮转。
who
w
grep "Accepted publickey\|Accepted password" /var/log/auth.log
示例输出:
Jan 20 10:01:22 debian sshd[1234]: Accepted password for root from 192.168.1.100 port 22
Debian 默认会轮转日志:
ls /var/log/auth.log*
查看旧日志:
zcat /var/log/auth.log.1.gz
# 统计失败登录最多的 IP
grep "Failed password" /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -nr | head
| 目的 | 命令 |
|---|---|
| 当前登录 | who / w |
| 登录历史 | last |
| 失败登录 | lastb / journalctl -u ssh |
| SSH 登录日志 | /var/log/auth.log |
| systemd 日志 | journalctl |
如果你是想 排查暴力破解 / 异常登录 / 服务器被入侵,可以告诉我,我可以帮你一步步分析日志。