我希望特定的用户组能够作为特定用户使用 su 命令。
例子)
团体 | 用户 |
---|---|
allowsu_aa |
aa |
allowsu_bb |
bb |
allowsu_cc |
cc |
所以我将以下内容添加到/etc/pam.d/su
文件中。
auth [success=2 default=ignore] pam_succeed_if.so user = aa
auth [success=2 default=ignore] pam_succeed_if.so user = bb
auth [success=2 default=3] pam_succeed_if.so user = cc
auth [success=done new_authtok_reqd=done default=2] pam_succeed_if.so use_uid user ingroup allowsu_aa
auth [success=done new_authtok_reqd=done default=1] pam_succeed_if.so use_uid user ingroup allowsu_bb
auth [success=done new_authtok_reqd=done default=ignore] pam_succeed_if.so use_uid user ingroup allowsu_cc
但它并没有按照我的意愿工作。
我应该如何修复它?
答案1
这里有一个很好的描述如何做到这一点:https://www.howtoing.com/switch-user-account-without-password/ 我测试成功了(Rocky Linux 9)。 PAM 相当……复杂(对我来说)。您还必须注意配置行在文件中的位置。当我的用户是 test_group 的成员时,我可以无需密码切换到 test_user
cat /etc/pam.d/su
#%PAM-1.0
auth required pam_env.so
auth sufficient pam_rootok.so
##### START
auth [success=ignore default=1] pam_succeed_if.so user = test_user
auth sufficient pam_succeed_if.so use_uid user ingroup test_group
##### END
# 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 substack system-auth
auth include postlogin
account sufficient pam_succeed_if.so uid = 0 use_uid quiet
account include system-auth
password include system-auth
session include system-auth
session include postlogin
session optional pam_xauth.so
希望有帮助。