rootにsuできるユーザーを制限する

rootにsuできるユーザーを制限したい時もあると思います。
そんなときの設定です。


今回の環境はCentOS5.5です。

ユーザーの作成


ユーザー「myuser1」「myuser2」を作成します。

# egrep "myuser1|myuser2" /etc/passwd
myuser1:x:2000:2000::/home/myuser1:/bin/bash
myuser2:x:2001:2001::/home/myuser2:/bin/bash

# egrep "myuser1|myuser2" /etc/group
myuser1:x:2000:
myuser2:x:2001:
wheelグループへの追加


「/etc/group」 に設定されている wheel グループに
rootにsuすることを許可するユーザーを設定します。


今回は「myuser1」を許可します。

# grep "wheel" /etc/group
wheel:x:10:root,myuser1
/etc/pam.d/suの編集

「/etc/pam.d/su」を編集します。

以下の一行がコメントアウトされているので、コメントを解除して設定を有効にします。
「auth required pam_wheel.so use_uid」

# cat /etc/pam.d/su
#%PAM-1.0
auth            sufficient      pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth           sufficient      pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth            required        pam_wheel.so use_uid
auth            include         system-auth
account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet
account         include         system-auth
password        include         system-auth
session         include         system-auth
session         optional        pam_xauth.so

設定ファイルを書き変えると設定が有効になります。

確認


myuser1はrootにsu出来ます。

[myuser1@centos5 ~]$ su -
パスワード:
[root@centos5 ~]#


myuser2は正しいパスワードを入力してもrootにsuすることができません。

[myuser2@centos5 ~]$ su -
パスワード:
su: パスワードが違います
[myuser2@centos5 ~]$


今日はこんなところで。