ユーザーがnopasswordで1つの実行可能ファイルのみを使用してsudoを使用してすべての操作を実行できるようにする

ユーザーがnopasswordで1つの実行可能ファイルのみを使用してsudoを使用してすべての操作を実行できるようにする

sudoを使用してすべてのコマンドを実行できる必要があるLinuxユーザーがあり、1つの実行可能ファイルを除くすべてのコマンドのパスワードを要求する必要があります。現在私の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最初の行が必要です。 2行目では%sudoパスワードですべてを実行できますが、最初の行が優先されるため、スクリプトを除くすべての項目は最初の行にパスワードを入力する必要があります。

%sudo    ALL=(root) NOPASSWD:/bin/switch.sh
%sudo    ALL=(ALL) ALL

おすすめ記事