问题:
在linux操作系统中,如何限定其它的普通用户登陆到root下?
解决方法:
在默认的情况下,普通用户通过su -命令输入了正确的root密码,就可以登陆到root用户下,对系统进行管理和配置。为了加强系统的完全性,使用linux特殊的用户组wheel,来实现这个功能,只有加入到wheel组,才可以使用su切换到root用户下。
redhat与centos系统:
1.查看系统中的wheel组
1
2
|
[root@node1 ~]
# cat /etc/group | grep wheel
wheel:x:10:
|
2.进行操作
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
useradd
a1
useradd
a2
usermod
-g wheel a1
cp
-a
/etc/pam
.d
/su
{,.bak}
#对配置文件进行备份
vim
/etc/pam
.d
/su
auth required pam_wheel.so use_uid
#取消这行注释
cp
-a
/etc/login
.defs{,.bak}
#对配置文件进行备份
echo
"SU_WHEEL_ONLY yes"
>>
/etc/login
.defs
#a1用户可以进行su到root用户
[root@node1 ~]
# su - a1
[a1@node1 ~]$
[a1@node1 ~]$
[a1@node1 ~]$
su
-
Password:
[root@node1 ~]
#
#a2用户不能su到root用户,即使输入正确root密码
[root@node1 ~]
# su - a2
[a2@node1 ~]$
[a2@node1 ~]$
[a2@node1 ~]$
su
-
Password:
su
: incorrect password
|
suse系统:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
cp -a /etc/pam .d /su-l {,.bak} #备份配置文件
vim /etc/pam .d /su-l
auth sufficient pam_rootok.so
auth required pam_wheel.so group=wheel use_uid #增加这一行
auth include common-auth
account include common-account
password include common-password
session include common-session
session optional pam_xauth.so
如果要设置用户切换到root时无需输入口令,则增加下面行
auth sufficient pam_wheel.so trust use_uid
|