在RHEL/CentOS上如何只允许Wheel组的用户使用su命令

时间:2019-08-20 17:58:05  来源:igfitidea点击:

wheel group是一个特殊的管理组
我们将设置只有wheel组的成员可以使用su切换到其他用户。

添加用户

使用“usermod”命令将一些用户添加到 wheel组中

语法:

usermod -a -G wheel username

例如,下面的例子中将把用户Hyman添加到wheel组中

[root@localhost ~]# usermod -a -G wheel Hyman
[root@localhost ~]# id Hyman
uid=500(Hyman) gid=500(Hyman) groups=500(Hyman),10(wheel)
[root@localhost ~]#

编辑/etc/pam.d/su文件

建议将/etc/pam.d/su备份到桌面或者主目录:

cp -p /etc/pam.d/su /root/etc-pamd-su

取消/etc/pam.d/su中下面行的注释

auth		required	pam_wheel.so use_uid

下面的例子中, test用户无法使用“su”命令。原因是用户test不是组wheel的成员 。

[test@localhost ~]$ id test
uid=501(test) gid=501(test) groups=501(test)
[test@localhost ~]$ 
[test@localhost ~]$ su
Password: 
su: incorrect password
[test@localhost ~]$ 
[test@localhost ~]$ su -l Hyman
Password: 
su: incorrect password
[test@localhost ~]$