先将用户加入wheel组
[root@localhost ~]# usermod -a -G wheel 用户名
[root@localhost ~]# id 用户名 # 检查用户是否加入wheel组
修改/etc/pam.d/su文件
[root@localhost ~]# vim /etc/pam.d/su
#%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 # 启用这条规则可以使wheel组的用户在切换到root用户时无需输入密码
# Uncomment the following line to require a user to be in the "wheel" group.
auth required pam_wheel.so use_uid # 启用这条规则可以限制只有wheel组的用户可以切换到root用户
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
[root@localhost ~]#
备注:此时加入了wheel组的用户执行“su -”命令切换到root用户时就不需要再输入密码了。
如需将用户移出wheel组可执行下面的命令
[root@localhost ~]# gpasswd -d 用户名 wheel