0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Linux基本設定】 sudo許可設定

Last updated at Posted at 2025-03-11

目的

・sudoers.dファイルを理解する
・特定のグループ/ユーザーにのみ、sudoを許可する
・ユーザーのsudoできるコマンドを限定する

sudo許可グループ

ubuntuでは 『sudo』グループ
rhel では 『wheel』グループ
に入っているユーザーはデフォルトdwsudoコマンドが可能となる

sudo設定ファイル編集

sudoの設定ファイルは/etc/sudoers

しかし、このファイルは超重要であるためvi/nanoで編集できない

以下のコマンドで編集可能となる

sudo visudo

sudoers.d直下に個別にファイルを置くことでもsudo設定は可能だが本記事では触れない

visudoはsudoers専用のエディタとなっており、sudoersの編集結果に構文的な誤りなどがある場合は検知してくれる

sudoersの設定項目

ユーザーへのsudo許可

ユーザー ホスト=(実行ユーザー) コマンド

user1に全ホスト、ユーザーとして全コマンドでsudoを許可する(パスワード不要)

user1 ALL=(ALL) NOPASSWD: ALL

user2にwebserverというホストにApacheの再起動コマンドのみでsudoを許可させる場合(パスワード必要)

user2 ALL=(ALL) /usr/bin/systemctl restart apache2

エイリアス

ここではコマンドエイリアスのみ記載

Cmnd_Alias SHUTDOWN = /sbin/shutdown, /sbin/reboot

ファイル内でコマンドを変数みたいに扱える

sudoできるコマンドをユーザー/グループ単位で分けておくことで事故を減らせるはず

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?