ルートになれるユーザーを制限する
安全性を高めるには「su」でルートになれるユーザーを制限すべきだ。標準の状態では、ログインしたユーザーは誰でも「su」コマンドを実行し、rootのパスワードを入力すれば、スーパーユーザーとしてあらゆる操作ができるようになる。
だが「su」コマンドがあると知ったユーザーは興味本位で辞書の単語を片っ端から試すかもしれない。そのうち本当のパスワードにぶちあたるかもしれない。そして、そのパスワードを悪い人に売りに行くかもしれない。
管理を行わない一般ユーザーがスーパーユーザーになれないように設定しておけば、正しいパスワードを入力してもエラーメッセージが表示される。こうしておけばサーバーの安全性がいたずらっ子におびやかされる危険性はぐんと低まる。
スーパーユーザーになれるユーザーを制限するには、管理を行うユーザーを「wheel」グループに追加し、「wheel」グループだけがスーパーユーザーになれるように設定する。
まずは「/etc/group」を編集して、「wheel」グループに管理を行うユーザーを追加しよう。
/etc/group
root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
sys:x:3:root,bin,adm
adm:x:4:root,adm,daemon
tty:x:5:
disk:x:6:root
lp:x:7:daemon,lp
mem:x:8:
kmem:x:9:
wheel:x:10:root,×× ←ここに管理を行うユーザー名を加える
mail:x:12:mail
news:x:13:news
uucp:x:14:uucp
:
次に「wheel」グループだけがスーパーユーザーになれるように「/etc/login.defs」と「/etc/pam.d/su」を編集する。
/etc/login.defs
:
:
#
# If useradd should create home directories for users by default
# On RH systems, we do. This option is ORed with the -m flag on
# useradd command line.
#
CREATE_HOME yes
SU_WHEEL_ONLY yes ←最後にこの1行を追加する
/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