【发布时间】:2019-06-07 20:19:45
【问题描述】:
在 Raspberry Pi 上,我希望来宾用户能够运行需要 sudo 权限的单个 python 脚本,但无需使用密码即可运行其他需要 sudo 权限的脚本。
我已使用 viuser 编辑了 /etc/sudoer 文件,但未能获得所需的结果。当我以“访客”身份登录并尝试运行脚本时,计算机会要求输入超级用户密码。
编辑后的 /etc/sudoer 文件如下:
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults
secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:$
# Host alias specification
# User alias specification
User_Alias GROUPONE = guest
# Cmnd alias specification
Cmnd_Alias SCRIPT = /home/guest/test.py
GROUPONE ALL = SCRIPT
# User privilege specification
root ALL=(ALL:ALL) ALL
GROUPONE ALL = NOPASSWD: /home/guest/test.py
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
python脚本是:
import subprocess
def Go():
subprocess.call(['sudo','echo', 'Test string'])
if __name == '__main__':
Go()
“python test.py”的预期结果是控制台上的“测试字符串”。 而是计算机请求访客 sudo 密码。
【问题讨论】:
标签: linux permissions