【问题标题】:Starting systemd service without password [closed]没有密码启动systemd服务[关闭]
【发布时间】:2019-02-12 18:04:40
【问题描述】:

我正在尝试使用 systemctl 启动我的 exampleService.service,而不以 root 身份登录。我创建了名为 testGroup 的组并在那里添加了我的帐户 - testAccount。我的服务文件位于 /etc/systemd/system 并且我有在/etc/sudoers.d 中创建了文件testConfig,内容如下:

 %testAccount ALL= NOPASSWD: /etc/systemd/system start exampleService.service
 %testAccount ALL= NOPASSWD: /etc/systemd/system stop exampleService.service
 %testAccount ALL= NOPASSWD: /etc/systemd/system restart exampleService.service

#includedir /etc/sudoers.d 行也存在于 sudoers 文件中。现在,当我尝试以以下身份启动服务时:systemctl start exampleService.service(以testAccount 登录)我会弹出输入密码,但它应该' t 是必需的。我的配置中的问题可能出在哪里?

【问题讨论】:

  • 您正在运行以启动服务的命令是 /bin/systemctl(或者可能是 /sbin/systemctl/usr/bin/systemctl,取决于发行版),所以这是您需要加入白名单的命令,而不是 /etc/systemd/system . sudo 不知道systemctl start exampleService.service/etc/systemd/system 目录有什么关系。

标签: linux service systemd


【解决方案1】:

在 /etc/sudoers 文件中添加以下行
testAccount ALL= NOPASSWD: ALL

【讨论】:

  • 这会将任何命令列入白名单,包括sudo systemctl poweroffsudo rm -rf /*sudo su。如果您完全关心系统的安全性,请不要这样做。 (即使您不关心系统的安全性,不安全的系统仍然对其他人构成威胁。)
猜你喜欢
  • 2014-03-16
  • 2018-05-31
  • 2021-01-08
  • 2015-11-17
  • 2015-06-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多