File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -467,7 +467,14 @@ systemd 中每个 session 都会启动一个用户级别的 systemd 进程,用
467467
468468 `systemctl`、`journalctl` 等命令依赖于 DBus 总线与 systemd 通信。对于用户 session 来说,则依赖于 session 的 DBus 服务正常工作(一般路径为 `/run/user/<用户 PID>/bus`)。
469469
470- 在某些非常特殊的环境下,可能需要配置 `XDG_RUNTIME_DIR=/run/user/<用户 PID>` 与 `DBUS_SESSION_BUS_ADDRESS=/run/user/<用户 PID>/bus` 环境变量,以便 `systemctl` 等命令能够正常工作。
470+ 在命令行下需要切换用户的场合中,如果需要使用用户级别的 systemd,推荐的做法是使用以下命令:
471+
472+ - `machinectl shell username@`
473+ - `run0`(需要很新的发行版,如 Debian 13)
474+
475+ 相关设计原因可阅读 <https://github.com/systemd/systemd/issues/7451#issuecomment-346787237>。注意,以上方法对非 root 使用 polkit 鉴权,与 sudo 配置无关。
476+
477+ 如果需要使用 `sudo` 或 `su` 切换用户,或者在某些非常特殊的环境下,可能需要自行配置 `XDG_RUNTIME_DIR=/run/user/<用户 PID>` 与 `DBUS_SESSION_BUS_ADDRESS=/run/user/<用户 PID>/bus` 环境变量,以便 `systemctl` 等命令能够正常工作。
471478
472479有些场景下,我们希望在机器启动时,用户 session 也能够创建,并且即使用户注销也不销毁。此时需要使用 lingering 的功能。使用 ` loginctl enable-linger <user> ` 命令即可启用。
473480
You can’t perform that action at this time.
0 commit comments