linux禁止普通用户su到root用户

简介:

问题:

    在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
本文转自   a8757906   51CTO博客,原文链接:http://blog.51cto.com/nxyboy/1971604
相关文章
|
1月前
|
Shell Linux
Linux:用户切换指令su
Linux:用户切换指令su
33 1
|
1月前
|
Oracle 关系型数据库 Linux
Linux下 su命令与su - 命令有什么区别?
Linux下 su命令与su - 命令有什么区别?
27 0
|
1月前
|
安全 Shell Linux
【Shell 命令集合 系统管理 】Linux 切换当前用户身份为另一个用户 su命令 使用指南
【Shell 命令集合 系统管理 】Linux 切换当前用户身份为另一个用户 su命令 使用指南
42 1
|
3月前
|
Shell Linux Perl
将 Linux 系统中 UID 大于等于 1000 的普通用户都删除shell脚本
将 Linux 系统中 UID 大于等于 1000 的普通用户都删除shell脚本
42 1
|
3月前
|
Linux 数据安全/隐私保护
Linux中普通用户使用sudo命令提示lin is not in the sudoers file. This incident will be reported.
Linux中普通用户使用sudo命令提示lin is not in the sudoers file. This incident will be reported.
|
1月前
|
安全 Shell Linux
【Shell 命令集合 系统管理 】Linux 以超级用户(root)的身份执行特权命令 sudo命令 使用指南
【Shell 命令集合 系统管理 】Linux 以超级用户(root)的身份执行特权命令 sudo命令 使用指南
42 1
|
3月前
|
Shell Linux
linux shell脚本判断当前登录用户是否为root
linux shell脚本判断当前登录用户是否为root
52 1
|
2月前
|
安全 Linux 数据安全/隐私保护
Linux命令 su 和 sudo 的区别
【2月更文挑战第5天】
33 0
Linux命令 su 和 sudo 的区别
|
3月前
|
Linux Shell 数据安全/隐私保护
linux命令之sudo/su
linux命令之sudo/su
34 7
|
3月前
|
Linux 应用服务中间件 数据安全/隐私保护
Linux - 非root用户使用systemctl管理服务
Linux - 非root用户使用systemctl管理服务
122 0