ユーザーが sudo を使用して何でも実行できるようにする (nopassword として実行可能ファイルは 1 つだけ)

ユーザーが sudo を使用して何でも実行できるようにする (nopassword として実行可能ファイルは 1 つだけ)

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

関連情報