大网数据广告活动
服务器运维问答

I don't see SSH disconnect events with `journalctl -u sshd`

· 52CE 我爱测

I want to monitor SSH sessions, including login and logout events. When I run journalctl without any flags, I see both login events like: Accepted publickey for root from 192.168.1.24 port 56464 and logout events like: Disconnect…

问题原文

原帖链接 · Pavel Anni · CC BY-SA 4.0

I want to monitor SSH sessions, including login and logout events. When I run journalctl without any flags, I see both login events like:

Accepted publickey for root from 192.168.1.24 port 56464

and logout events like:

Disconnected from user root 192.168.1.24 port 56464

But when I want to reduce the output and filter only the sshd events I run journalctl -u sshd. In this case I see only the Accepted publickey events, but not the Disconnected from user events.

社区高分解答

原帖链接 · Pavel Anni · CC BY-SA 4.0

TL;DR: Instead of journalctl -u sshd you should use journalctl -t sshd.

To figure out that, I ran journalctl -o json-pretty and analyzed login and logout events. The login events have "_SYSTEMD_UNIT" : "sshd.service" in their JSON output, so they show up when you specify the unit with -u sshd. But the logout events have "_SYSTEMD_UNIT" : "session-27.scope", and that's why they are not shown for -u sshd. Of course, the session number is different for each SSH session.

What is common for both logout and login events is "SYSLOG_IDENTIFIER" : "sshd" which means we have to use the -t flag (or long-form --identifier) to specify the identifier.

This is on Fedora and RHEL. I haven't tested it on Debian/Ubuntu yet. Please comment if it's different there.

I hope this will help somebody.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-05-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。