VPS

su コマンドを制限する

投稿日:

suコマンドは、別のユーザアカウントに権限を切り替えるためのコマンドです。Linux系OS の標準設定では、root のパスワードさえ知ってしまえば、一般ユーザでも root になれます。この状態は、セキュリティ的に良い状態ではありません。今回は、wheel グループに属するユーザのみ su コマンドを実行できるように制限する方法を解説します。

スポンサーリンク

pam_wheel.so を利用して実行できるユーザを制限する

設定方法

/etc/pam.d/su を編集する。

$ sudo vi /etc/pam.d/su

6行目のコメント(#)を外す。

#%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

検証

許可されていないユーザが su を実行すると、以下のとおり拒否されます。

$ su
パスワード:
su: incorrect password

補足説明

  1. PAM 利用上の注意点
  2. /etc/ssh/sshd_config の「ChallengeResponseAuthentication yes」になっていると鍵認証が失敗した場合、 PAM のパスワード認証が有効になり、セキュリティが低下します。「ChallengeResponseAuthentication no」になっているか確認が必要です。

  3. SU_WHEEL_ONLY の設定は不要
  4. サイトによっては、pam_wheel.so と SU_WHEEL_ONLY の両方の設定が必要な説明がありますが、最近のLinuxのデストリビューションでは、SU_WHEEL_ONLY の設定は不要になったようです。(CentOS5.5 で確認済)

-VPS
-,

Copyright© 気になるボックス , 2023 AllRights Reserved Powered by AFFINGER4.