我如何允许普通用户在Ubuntu 16.04上停止Postgresql?

我的用户是'peaagent'。 我已经尝试visudo -f /etc/sudoers.d/peaagent与以下内容:

 peaagent ALL = (root) NOPASSWD: /bin/systemctl stop postgresql.service 

当我尝试停止Postgresql作为peaagent它会提示我input密码:

 peaagent@myserver:~$ /bin/systemctl stop postgresql.service ==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units === Authentication is required to stop 'postgresql.service'. Authenticating as: root Password: 

任何人都知道为什么这不起作用? TX。

你的问题是,你不是sudo前缀的命令。 当你试图运行没有足够权限的systemd命令时,systemd会要求一个密码(通过systemd-ask-password)给一个适当的特权帐户。

 sudo /bin/systemctl stop postgresql.service 

应该做你想做的。