天天看点

只允许特定的组用户su切换到root

linux系统root具有至高无上的权限,工作生产环境或者VPS一般为了安全起见,禁止root登录,禁止root用户权限,使用普通用户登录,有特殊需求可以su或sudo切换到root权限进行操作,下面介绍一个方法只允许特定的组用户su切换到root:

1、新建普通用户,比如baby

1

<code>useradd</code>  <code>baby</code>

2、修改密码

<code>passwd</code> <code>baby</code>

3、将帐号加入wheel组

<code>usermod</code> <code>-G wheel baby</code>

4、设置只允许这个组的帐号,使用su命令切换到root

vi /etc/pam.d/su

找到#auth            required        pam_wheel.so use_uid

去掉行首的注释符 # 保存退出;

接着vi /etc/login.defs

在最末添加SU_WHEEL_ONLY yes 保存退出即可。

或者执行 

<code>echo</code> <code>"SU_WHEEL_ONLY yes"</code><code>&gt;&gt;</code><code>/etc/login</code><code>.defs</code>

现在,再建立新的普通帐号,是无法使用su命令切换到root组了。

实验验证:

2

3

4

5

6

7

8

9

10

11

12

13

<code>[root@localhost ~]</code><code># su - baby</code>

<code>[baby@localhost ~]$ </code><code>whoami</code>  

<code>baby</code>

<code>[baby@localhost ~]$ </code><code>su</code> <code>-</code>

<code>Password:</code>

<code>[root@localhost ~]</code><code># whoami</code>

<code>root</code>

<code>[root@localhost ~]</code><code># su - anglea</code>

<code>[anglea@localhost ~]$ </code><code>whoami</code>

<code>anglea</code>

<code>[anglea@localhost ~]$ </code><code>su</code> <code>-</code>

<code>su</code><code>: incorrect password</code>

baby属于wheel组,wheel组的用户只允许su切换到root;anglea不属于wheel组,正确输入root的密码也提示不正确的密码,无法切换到root;

本文转自 模范生 51CTO博客,原文链接:http://blog.51cto.com/mofansheng/1687923,如需转载请自行联系原作者

继续阅读