非 root 用户的 journalctl 访问

mik*_*ike 15 journald journalctl

journald 文档说将用户添加到“systemd-journal”组或“adm”组允许用户访问系统范围的日志。

我正在运行最新的 CentOS 7,但我似乎无法以非 root 用户身份访问日志。

这是我的配置:

$ id
uid=1000(centos) gid=1000(centos) groups=1000(centos),4(adm),10(wheel),190(systemd-journal) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

$ cat /etc/systemd/journald.conf
[Journal]
Storage=persistent

$ journalctl
-- Logs begin at Sat 2015-08-29 16:35:52 UTC, end at Sat 2015-08-29 17:28:47 UTC. --
Aug 29 16:35:52 hostname ... <log continues>
Run Code Online (Sandbox Code Playgroud)

journalctl 输出中没有系统日志。这是我的权限配置:

$ ll -a /var/log/journal/f9afeb75a5a382dce8269887a67fbf58/
total 24592
drwxr-xr-x. 2 root root     4096 Aug 29 16:35 .
drwxr-xr-x. 3 root root     4096 Aug 29 17:28 ..
-rw-r-----. 1 root root 16777216 Aug 29 17:27 system.journal
-rw-r-----+ 1 root root  8388608 Aug 29 17:33 user-1000.journal
Run Code Online (Sandbox Code Playgroud)

如果我将所有权组更改system.journalsystemd-journal一切正常。然而,这似乎不对,因为文档没有对此进行任何说明。

有什么我遗漏的system.journal吗,或者实际上是否需要手动更改文件组?

谢谢

mik*_*ike 7

解决方案是.journal在创建文件之前更改组所有权并在父文件夹中添加一个粘性位。

chown :systemd-journal /var/log/journal/f9afeb75a5a382dce8269887a67fbf58
chmod g+s /var/log/journal/f9afeb75a5a382dce8269887a67fbf58
Run Code Online (Sandbox Code Playgroud)


小智 5

好吧,我没有运行 Centos 7,但发现了这个问题。我执行了这些步骤,但没有帮助,至少在 Ubuntu 18.04 上我收到一条消息:

Hint: You are currently not seeing messages from other users and the system.
      Users in groups 'adm', 'systemd-journal' can see all messages.
      Pass -q to turn off this notice.
Run Code Online (Sandbox Code Playgroud)

因此,我sudo usermod -a -G systemd-journal my_user确实退出(从 ssh)并重新登录以使组更改生效,之后我可以使用普通用户查看日志消息。