suで root になれるユーザーを制限

どのユーザーも su コマンドで root になれるのはちょっとまずいので、特定のユーザーだけがなれるように制限します。

/etc/pam.d/su の設定


#%PAM-1.0
auth sufficient /lib/security/pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient /lib/security/pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth required /lib/security/pam_wheel.so use_uid
auth required /lib/security/pam_stack.so service=system-auth
account required /lib/security/pam_stack.so service=system-auth
password required /lib/security/pam_stack.so service=system-auth
session required /lib/security/pam_stack.so service=system-auth
session optional /lib/security/pam_xauth.so
 

赤文字の部分をコメントアウト。もしくは追加

/etc/login.defs


一番最後に追加

SU_WHEEL_ONLY yes
 

これで、wheel グループしかsu出来ない

/etc/group


wheel:x:10:root,kazan
 

対象ユーザーを追加します。
wheelグループがない場合は作りましょう。

wheel グループ以外がsuを使うと、パスワードは入力できるが、正しいのを入れても
su: incorrect password
となります。