如果不想任何人都可以用su
命令成为root或只让某些用户有权使用su命令,那么只需要修改/etc/pam.d/su
文件中配置即可实现.建议尽量限制用户通过su命令成为root。
1.对/etc/pam.d/su
进行如下修改。
[root@svr5 shell]# 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
# 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
注意:/etc/pam.d/su
配置文件中定义了wheel
组,wheel
组是系统中用于这个目的的特殊帐号.不能用别的组名.
2.创建用户lian和lian1 用来测试效果
[root@svr5 shell]# useradd lian
[root@svr5 shell]# useradd lian 1
3.将用户lian加入到wheel组
[root@svr5 shell]# usermod -G 10 lian
[root@svr5 shell]# id lian
uid=500(lian) gid=500(lian) 组=500(lian),10(wheel)
查看用户lian的属性
[root@svr5 shell]# id lian1
uid=504(lian1) gid=505(lian1) 组=505(lian1)
4.首先使用用户lian登陆系统,并使用su切换。
5.然后再使用用户lian1登陆系统切换,提示密码错误。