LoginSignup
154
184

More than 5 years have passed since last update.

CentOSでuserをsudo可能にする

Last updated at Posted at 2016-05-31

環境

  • CentOS release 6.7 (Final)

手順

ユーザー追加、パスワード設定

$ useradd sampleuser
$ passwd sampleuser

visudoで/etc/sudoersを開き、下記の行のコメントアウトを外す。

$ visudo

## Allows people in group wheel to run all commands
%wheel  ALL=(ALL)       ALL

sudoの実行をパスワードなしで許可する場合は、下記のほうのコメントアウトを外す。

# Same thing without a password
%wheel        ALL=(ALL)       NOPASSWD: ALL

ユーザーをwheelグループに追加

$ usermod -aG wheel sampleuser

sampleuserになって、自分の所属groupを確認

$ groups
sampleuser wheel

sampleuserでログインし、rootになってみる

$ sudo su - 
[sudo] password for sampleuser:{sampleuserのパスワード}

$ whoami
root

特定のユーザーのみsudoを許可する

username   ALL=(ALL)   NOPASSWD: ALL

suでrootになれるようにする

wheelグループのユーザーはすべてsu -でrootになれるようにする

/etc/pam.d/su
-#auth            required        pam_wheel.so use_uid
+auth            required        pam_wheel.so use_uid

以上

参考

154
184
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
154
184