A little bit of everything

元・情報系大学院生の備忘録

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

ユーザが複数いる場合、全員がroot になれてしまうと、セキュリティ的によろしくない。そこで、root になれるユーザを限定する。

これは、/etc/pam.d/su の中身を変更すればできる。

#
# The PAM configuration file for the Shadow `su' service
#

# This allows root to su without passwords (normal operation)
auth       sufficient pam_rootok.so

# Uncomment this to force users to be a member of group root
# before they can use `su'. You can also add "group=foo"
# to the end of this line if you want to use a group other
# than the default "root" (but this may have side effect of
# denying "root" user, unless she's a member of "foo" or explicitly
# permitted earlier by e.g. "sufficient pam_rootok.so").
# (Replaces the `SU_WHEEL_ONLY' option from login.defs)
# auth       required   pam_wheel.so   ←ここのコメントをはずす

(略)

コメントをはずそう。

#
# The PAM configuration file for the Shadow `su' service
#

# This allows root to su without passwords (normal operation)
auth       sufficient pam_rootok.so

# Uncomment this to force users to be a member of group root
# before they can use `su'. You can also add "group=foo"
# to the end of this line if you want to use a group other
# than the default "root" (but this may have side effect of
# denying "root" user, unless she's a member of "foo" or explicitly
# permitted earlier by e.g. "sufficient pam_rootok.so").
# (Replaces the `SU_WHEEL_ONLY' option from login.defs)
auth       required   pam_wheel.so   ←こうね。

(略)

そうするとwheelグループの人しかsuできないようになる。

自分の場合はwheelグループがデフォルトで存在しなかったので、作った。
groupadd wheel
で、suを使えるようにしたいユーザをwheelに入れる。
usermod -G wheel user01
(ちなみに -G オプションはPrimary Group以外のグループ変更をするときに使う。Primary Group変更 は小文字の -g オプション。)
これでuser01はwheelグループに入ったので、suを使えるようになる。

すでにwheelみたいな役割のグループが存在している場合

すでにwheelみたいな役割のグループが存在しているなら、そのグループに所属する人に対してのみsuを許可するようにできる。その場合は、/etc/pam.d/su の中身で、

auth required pam_wheel.so

の後ろに「group=グループ名」を追加する。

#
# The PAM configuration file for the Shadow `su' service
#

# This allows root to su without passwords (normal operation)
auth       sufficient pam_rootok.so

# Uncomment this to force users to be a member of group root
# before they can use `su'. You can also add "group=foo"
# to the end of this line if you want to use a group other
# than the default "root" (but this may have side effect of
# denying "root" user, unless she's a member of "foo" or explicitly
# permitted earlier by e.g. "sufficient pam_rootok.so").
# (Replaces the `SU_WHEEL_ONLY' option from login.defs)
auth       required   pam_wheel.so group=group01  ←こんなかんじで。

(略)

こうすると、wheelの代わりにgroup01に所属しているユーザが、suが使えるようになる。