Skip to content

Instantly share code, notes, and snippets.

@Wind4
Last active April 3, 2019 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Wind4/f272c4890298d2dc1ded to your computer and use it in GitHub Desktop.
Save Wind4/f272c4890298d2dc1ded to your computer and use it in GitHub Desktop.
CentOS禁止非WHEEL用户使用SU命令
[root@localhost ~]#useradd -M -s /sbin/nologin -n username
[root@localhost ~]#passwd username

为了更进一步加强系统的安全性,有必要建立一个管理员的组,只允许这个组的用户来执行“su -”命令登录为root用户,而让其他组的用户即使执行“su -”、输入了正确的root密码,也无法登录为root用户。 在UNIX和Linux下,这个组的名称通常为“wheel”。

1: 添加一个用户加入Wheel组

[root@localhost ~]# useradd -G wheel username

2: 修改用户密码

[root@localhost ~]# passwd username

3: 修改/etc/pam.d/su配置

[root@localhost ~]# vi /etc/pam.d/su # 打开这个配置文件

4.找到此行,去掉行首的“#”

auth required pam_wheel.so use_uid

5: 修改/etc/login.defs文件

[root@localhost ~]# echo “SU_WHEEL_ONLY yes” >> /etc/login.defs #

添加语句到行末以上操作完成后,可以再建立一个新用户,然后用这个新建的用户测试会发现,没有加入到wheel组的用户,执行“su -”命令,即使输入了正确的root密码,也无法登录为root用户。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment