Linux 无密码启动systemd服务

Linux 无密码启动systemd服务,linux,service,systemd,Linux,Service,Systemd,我正在尝试使用systemctl启动我的示例服务。服务,没有以root用户身份登录。我创建了名为testGroup的组,并在那里添加了我的帐户-testAccount。我的服务文件位于/etc/systemd/system,我在/etc/sudoers.d中创建了文件testConfig,内容如下: %testAccount ALL= NOPASSWD: /etc/systemd/system start exampleService.service %testAccount ALL= NO

我正在尝试使用systemctl启动我的
示例服务。服务
,没有以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

另外,sudoers文件中有一行
#includedir/etc/sudoers.d
。现在,当我尝试以以下方式启动服务:
systemctl start exampleService.service
(以
testAccount
登录)时,我会弹出窗口输入密码,但它不应该是必需的。我的配置中的问题在哪里?

在/etc/sudoers文件的下面一行添加

testAccount ALL=NOPASSWD:ALL

启动服务所运行的命令是
/bin/systemctl
(或者
/sbin/systemctl
或者
/usr/bin/systemctl
,具体取决于发行版),因此这是您需要列入白名单的命令,而不是
/etc/systemd/system
。sudo不知道
systemctl start exampleService。service
/etc/systemd/system
目录有关。这将白名单上任何命令,包括
sudo systemctl poweroff
sudo rm-rf/*
sudo su
。如果您关心系统的安全性,请不要这样做。(即使您不关心系统的安全性,不安全的系统仍然会对其他人构成威胁。)