cat /etc/sudoers で sudoers ファイルを確認する
このステップでは、sudo
の主要な設定ファイルである /etc/sudoers
ファイルを調べます。このファイルは、どのユーザーまたはグループがどのユーザーとしてどのコマンドを実行できるかを決定します。
重要: /etc/sudoers
ファイルを直接編集することは危険であり、誤って編集するとシステムからロックアウトされる可能性があります。一般的には、構文チェック機能を備えた visudo
コマンドを使用してこのファイルを編集することが推奨されます。ただし、このステップでは、cat
コマンドを使用してファイルの内容を単に表示し、その構造を理解します。
/etc/sudoers
はシステムファイルであるため、読み取るには sudo
権限が必要です。
ターミナルに以下のコマンドを入力し、Enter キーを押します。
sudo cat /etc/sudoers
/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
## 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
%sudo ALL=(ALL:ALL) ALL
という行は特に重要です。これは、sudo
グループ (%sudo
) のメンバーであるすべてのユーザーが、任意のホスト (ALL
) で任意のユーザー (ALL
) および任意のグループ (ALL
) としてコマンド (ALL
) を実行できることを意味します。これは、Ubuntu のような Debian ベースのシステムでユーザーに管理権限を付与する一般的な方法です。
このファイルを表示することで、システム上の sudo
権限の設定方法を理解することができます。
続ける をクリックして次のステップに進みます。