首页 > 解决方案 > 无密码启动 systemd 服务

问题描述

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

 %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)我会弹出输入密码,但它不应该是必需的。我的配置中的问题可能出在哪里?

标签: linuxservicesystemd

解决方案


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


推荐阅读