如何访问 systemd 的根日志?

如何访问 systemd 的根日志?

journalctl -f -a当我在 Fedora 20 下为不同用户执行时,我得到不同的结果。对于root,我得到了tail -f /var/log/syslog与旧系统类似的东西。作为普通用户,我收到 gnome-shell 警告、一些 su 消息、Firefox 写入标准输出的内容等 - 基本上是用户会话日志。

据我了解,journalctl有不同期刊的概念(journalctl(1)):

所有可访问的日志文件的输出都是交错的,无论它们是轮换的还是当前正在写入的,也无论它们是属于系统本身还是可访问的用户日志。

但是如何获取给定用户可用的期刊列表呢?

以及如何让普通用户也可以访问根日志?

Journalctl 手册页指出:

所有用户都有权访问其私人的每用户日记。但是,默认情况下,只有 root 和“systemd-journal”组成员的用户才能访问系统日志和其他用户的日志。

但这听起来太多了——用户不应该访问其他普通用户的日志(只能访问根日志)。

答案1

systemd-journald 手册页解释日志访问控制是如何完成的:

Journal files are, by default, owned and readable by the "systemd-journal"
system group but are not writable. Adding a user to this group thus enables
her/him to read the journal files.

By default, each logged in user will get her/his own set of journal files in
/var/log/journal/. These files will not be owned by the user, however, in order
to avoid that the user can write to them directly. Instead, file system ACLs
are used to ensure the user gets read access only.

Additional users and groups may be granted access to journal files via file
system access control lists (ACL).

Fedora 20 使用 ACL 授予admwheel组中的用户对所有日志的读取权限。

如何让普通用户也可以访问根日志?

跑步setfacl -n -m u:username:r /var/log/journal/*/system.journal

如何获取给定用户可用的期刊列表?

您可以su向用户运行并journalctl --header|grep '^File Path'查看他或她有权访问的期刊名称。

getfacl可用于查看哪些组和用户有权访问日志文件。我不知道有什么简单的方法来列出特定用户可读的文件。

相关内容