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 コマンドについて ①

Posted at

この記事について

sudoコマンドやその設定ファイルについて整理する。

一般ユーザーへ管理用コマンド実行権限を委譲する

通常、管理用コマンドは一般ユーザーでは実行することができない。
/etc/sudoersを編集することで、sudoコマンドを用いた一般ユーザーでの管理用コマンドの実行が可能となる。

  • rootユーザーでvisudoコマンドを実行し、/etc/sudoersの編集画面に入る。
  [root@localhost ~]# visudo
  • 以下の行を追加する。これにより、sudoコマンドを用いた、一般ユーザーでのsystemctlコマンドの実行ができるようになる。
  Kotaro ALL=NOPASSWD: /usr/bin/systemctl

NOPASSWD の指定により、パスワード入力をせずにコマンドの実行ができるようになる。

  • 当該一般ユーザーで以下のコマンドを実行する。
    パスワードの入力をせずに、sudoコマンドを用いた管理用コマンドの実行ができた。
  [Kotaro@localhost ~]$ sudo systemctl status chronyd
● chronyd.service - NTP client/server
   Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2025-04-14 10:14:03 JST; 2 days ago
     Docs: man:chronyd(8)
           man:chrony.conf(5)
  Process: 861 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS)
  Process: 839 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 846 (chronyd)
    Tasks: 1 (limit: 23216)
   Memory: 2.2M
   CGroup: /system.slice/chronyd.service
           mq846 /usr/sbin/chronyd

実行可能コマンドの確認

  • 一般ユーザーで以下のコマンドを実行する。
  [Kotaro@localhost ~]$ sudo -l
  • 以下行より、当一般ユーザーが実行できる管理用コマンドを確認できる。
User Kotaro may run the following commands on localhost:
(root) NOPASSWD: /usr/bin/systemctl

以上。

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?