Linux的wheel组:Linux下用户使用su命令切换用户报错su: Permission denied
Linux的wheel组:LINUX下用户使用su命令切换用户报错su: Permission denied
通常情况下,一般用户通过执行“su -”命令、输入正确的root密码,可以登录为root用户来对系统进行管理员级别的配置。
但是,为了更进一步加强系统的安全性,有必要建立一个管理员的 组,只允许这个组的用户来执行“su -”命令登录为root用户,而让其他组的用户即使执行“su -”、输入了正确的root密码,也无法登录为root用户。在UNIX和Linux下,这个组的名称通常为“wheel”。
禁止非wheel组用户切换到root
1、 修改/etc/pam.d/su
配置,去掉#auth required pam_wheel.so use_uid
该行的注释,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@lhr ~]# cat /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 # 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 |
2、 修改/etc/login.defs文件
1 | echo "SU_WHEEL_ONLY yes" >> /etc/login.defs |
添加语句SU_WHEEL_ONLY yes
到文件的最后。
可以再建立一个新用户,然后用这个新建的用户测试会发现,没有加入到wheel组的用户,执行“su -”命令,即使输入了正确的root密码,也无法登录为root用户
3、 添加一个用户woo,测试是否可以切换到root
1 2 3 4 5 6 | [root@db01 ~]# useradd woo [root@db01 ~]# passwd woo Changing password for user woo. New UNIX password: BAD PASSWORD: it is WAY too shortRetype new UNIX password: passwd: all authentication tokens updated successfull |
4、通过woo用户登录尝试切换到root
1 2 | [woo@db01 ~]$ su - root ← 即使密码输入正确也无法切换Password: su: incorrect password [woo@db01 ~]$ |
5: 把root用户加入wheel组再尝试切换,可以切换
1 2 3 4 5 | [root@db01 ~]# usermod -G wheel woo ← 将普通用户woo加在管理员组wheel组中 [root@db01 ~]# su - woo [woo@db01 ~]$ su - root ← 这时候我们看到是可以切换了 Password: [root@db01 ~]# |