我正在运行 Ubuntu 18.04.2 LTS,并全新安装了transmission-daemon
。它作为 Systemd 服务运行良好。但是当我尝试独立运行它(服务停止)时,我看到:
~ ⌘ sudo -u debian-transmission transmission-daemon -f --log-error --log-info --log-debug
[2019-05-14 11:53:19.167] Couldn't read "/home/jason/.config/user-dirs.dirs": Permission denied
[2019-05-14 11:53:20.419] Couldn't create "/home/jason/.config/transmission-daemon": Permission denied (file-posix.c:189)
[2019-05-14 11:53:20.419] Couldn't create "/home/jason/.config/transmission-daemon": Permission denied (file-posix.c:189)
[2019-05-14 11:53:20.419] Couldn't create "/home/jason/.config/transmission-daemon": Permission denied (file-posix.c:189)
[2019-05-14 11:53:20.419] Transmission 2.92 (14714) started (session.c:740)
[2019-05-14 11:53:20.419] Couldn't read "/home/jason/.config/transmission-daemon/stats.json": No such file or directory (utils.c:238)
[2019-05-14 11:53:20.419] Couldn't read "/home/jason/.config/transmission-daemon/stats.benc": No such file or directory (utils.c:238)
请注意,~
确实解析/home/jason
为用户jason
(我)。但我以用户的身份运行它debian-transmission
。那么,为什么 Transmission 试图访问“我的”用户目录?我该如何阻止它这样做?
答案1
至少在最新版本的 Ubuntu 中,sudo
配置为保留调用用户的HOME
环境变量1。您可以通过执行类似以下操作来验证这一点
$ sudo -u testuser sh -c 'echo $HOME'
/home/steeldriver
或者通过运行sudo sudo -V
并查看该Environment variables to preserve
部分。
为了设置HOME
为目标用户,您可以添加-H
(--set-home
)选项:
-H, --set-home Request that the security policy set the HOME environment variable to the home directory specified by the target user's password database entry. Depending on the policy, this may be the default behavior.
前任。
$ sudo -Hu testuser sh -c 'echo $HOME'
/home/testuser