
我有一個 Linux 用戶,需要能夠使用 sudo 執行任何命令,但除了一個可執行檔之外,它應該詢問所有命令的密碼。目前我的 sudoers 文件如下所示:
#
# 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:/sbin:/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) NOPASSWD:/bin/switch.sh
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
所以我已將我的用戶添加到 sudo 群組,但是我認為我的語法錯誤,因為現在我只能使用 sudo 執行 switch.sh 而不能執行其他命令
答案1
對於%sudo
群組使用者來說,允許任何內容,但/bin/switch.sh
您需要第一行。第二行允許使用者%sudo
使用密碼執行所有內容,但由於第一行優先,因此使用者必須在第一行上輸入腳本以外的所有內容的密碼。
%sudo ALL=(root) NOPASSWD:/bin/switch.sh
%sudo ALL=(ALL) ALL