(Ubuntu)root以外のユーザーはrootアクセス権を持っていますが、sudoグループには属していません。

(Ubuntu)root以外のユーザーはrootアクセス権を持っていますが、sudoグループには属していません。

私のAWS EC2インスタンスのユーザーには無制限のsudoアクセス権があり、パスワードプロンプトはありません。これはUbuntu 20.04.4 LTS仮想マシンです。

問題の例は次のとおりです。

~$ whoami
ubuntu
~$ groups
ubuntu
~$ sudo deluser ubuntu sudo
/usr/sbin/deluser: The user `ubuntu' is not a member of group `sudo'.
~$ sudo whoami
root

ご覧のとおり、ユーザーを自分のグループ(ubuntu)以外のすべてのグループから削除しました。

これは私の/etc/sudoersファイルです:

~$ sudo cat /etc/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:/snap/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) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

%adminテストしたばかりの項目だけでなく、グループ項目もコメントしましたsecure_pathDefaults

コンピュータを再起動し、 で再度ログインしましたubuntu。それでもsudoアクセス権があり、制限なくルートに切り替えることができます。

$ sudo su
root@ip-x-x-x-x:/home/ubuntu#

rootユーザーするアカウントにパスワードがあります。

sudo新しいユーザーを追加してsudoを使用するには、この新しいユーザーをグループに追加する必要があることを確認しました。

それでは、私のユーザーにubuntu無料のrootアクセス権があるのはなぜですか?

ベストアンサー1

ファイルの末尾付近/末尾にこの行が表示されますか/etc/sudoers

#includedir /etc/sudoers.d

これにより、ディレクトリ内のファイルがロードされ、ファイルの一部として/etc/sudoers.d処理されます。/etc/sudoersこの行の上のコメント付きの行が示すように、sudoersファイルのマニュアルページでは、このディレクティブがどのように機能するかについて詳しく説明します#includedir

/etc/sudoers.dディレクトリ内のファイルを見ると、ubuntuユーザーにコマンドを呼び出す権限を与えるエントリを見つけることができますroot

おすすめ記事