Linux账户权限管理上为了防止普通用户通过su切换到root用户,需要修改/etc/pam.d/su和/etc/login.defs两个配置文件。

Step1:修改 /etc/pam.d/su文件

[root@ess ~]# vi /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 substack system-auth
auth include postlogin
account sufficient pam_succeed_if.so uid = 0 use_uid quiet
account include system-auth
"/etc/pam.d/su" 14L, 540C
#%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 substack system-auth
auth include postlogin
account sufficient pam_succeed_if.so uid = 0 use_uid quiet
account include system-auth
password include system-auth
session include system-auth
session include postlogin
session optional pam_xauth.so

Step2:修改/etc/login.defs,末尾追加SU_WHEEL_ONLY yes

#
# If defined, this command is run when removing a user.
# It should remove any at/cron/print jobs etc. owned by
# the user to be removed (passed as the first argument).
#
#USERDEL_CMD /usr/sbin/userdel_local

#
# If useradd should create home directories for users by default
# On RH systems, we do. This option is overridden with the -m flag on
# useradd command line.
#
CREATE_HOME yes

# The permission mask is initialized to this value. If not specified,
# the permission mask will be initialized to 022.
UMASK 077

# This enables userdel to remove user groups if no members exist.
#
USERGROUPS_ENAB yes

# Use SHA512 to encrypt password.
ENCRYPT_METHOD SHA512
SU_WHEEL_ONLY yes

Step3:使用普通账户登录系统进行su测试

[tom@ess ~]$ su -
密码:
su: 拒绝权限
[tom@ess ~]$

说明:其他需要有权限root的用户需要添加至wheel组中,如下图:

[root@ess ~]# usermod -G wheel networking

[root@ess ~]# id networking
uid=1001(networking) gid=1001(networking) 组=1001(networking),10(wheel)
[root@ess ~]#

Linux 禁止普通用户su到root的更多相关文章

  1. Linux禁止普通用户su至root

    linux系统为了限制权限,有时候需要禁止普通用户su到root用户 为禁止普通用户su至root,需要分别修改/etc/pam.d/su和/etc/login.defs两个配置文件. 二.详细配置 ...

  2. Linux安全加固(二)禁止普通用户su到root/设置SSH终端接入白名单/修改history条数

    一.禁止普通用户su到root管理员.设置可以su到root的白名单 1.首先看一下正常情况 2.可以看到普通用户使用su root命令,输入密码即可登录到root用户 3.下面开始配置禁止所有普通用 ...

  3. centOS禁止普通用户su到root

    1.关于su的相关权限涉及到两个文件,分别为/etc/pam.d/su和/etc/login.defs两个配置文件. 2.禁止普通用户su到root,配置如下: 去除/etc/pam.d/su文件中如 ...

  4. 普通用户su 到root,无需密码方式,及iptables封掉本机某个端口,core文件配置

    一. 普通用户su到root无需密码: 随着服务器越来越多,普通用户转到root下,去查密码表是个很繁琐的事,发现有如下方式比较方便(需要root操作) vi /etc/pam.d/su  将 aut ...

  5. linux下添加用户并赋予root权限

    1.添加用户,首先用adduser命令添加一个普通用户,命令如下: #adduser tommy //添加一个名为tommy的用户#passwd tommy   //修改密码Changing pass ...

  6. linux下加入用户并赋予root权限

    1.加入用户.首先用adduser命令加入一个普通用户,命令例如以下: #adduser tommy //加入一个名为tommy的用户 #passwd tommy   //改动password Cha ...

  7. Linux禁止普通用户使用crontab命令

    cron计划任务默认root用户与非root用户都可以执行,当然如果在安全方面想禁用这部分用户,则可以通过两个文件来解决: cron.allow cron.deny cron.allow:定义允许使用 ...

  8. Linux进入单用户模式(passwd root修改密码)

    进入单用户模式——passwd root修改密码 1.在grub 页面输入a,进入修改内核模式 2.在内核的结尾“/”,输入空格,在输入single,回车 3.启动系统,进入单用户模式 4.Passw ...

  9. linux禁止普通用户登录

    要想禁止普通用户登录 方法如下: 在 /etc下创建一个 nologin的文件 编辑这个文件,输入内容,当普通用户登录时就会提示这个文件的内容,并且禁止登陆. 执行步骤: touch /etc/nol ...

随机推荐

  1. 【mongodb】如何在mac上安装mongoDB

    1.登入MongoDB的官网 选择发布的版本 网址:https://www.mongodb.com/download-center/community 2.下载tgz的包,解压缩 3.打开终端,配置环 ...

  2. golang-grpc-Unimplemented-desc

    golang 调用grpc 服务方法时候提示:"rpc error: code = Unimplemented desc ="的错误, 这是由于pb中的package name 被 ...

  3. golang http proxy反向代理

    本文介绍golang中如何进行反向代理. 下面例子中, proxy server接收client 的 http request,转发给true server,并把 true server的返回结果再发 ...

  4. postgreSQL数据库limit分页、排序

    postgreSQL数据库limit分页.排序 语法: select * from persons limit  A  offset  B; 解释: A就是你需要多少行: B就是查询的起点位置. 示例 ...

  5. Python 输出

    普通的输出 生活中的“输出”: 软件中的“输出”: python中变量的输出: print('hello world') 格式化输出 占位符% print('Hello,%s' % 'Python') ...

  6. Class 泛型

    Java Class 泛型的例子说明: http://blog.chinaunix.net/uid-1911213-id-3085866.html http://blog.163.com/sir_87 ...

  7. Lock和synchronized的区别和使用

    Java并发编程:Lock 今天看了并发实践这本书的ReentantLock这章,感觉对ReentantLock还是不够熟悉,有许多疑问,所有在网上找了很多文章看了一下,总体说的不够详细,重点和焦点问 ...

  8. sxstrace启动.bat

    @echo offset dd=%date:~8,2%set mm=%date:~5,2%set yy=%date:~0,4%set Tss=%TIME:~6,2%set Tmm=%TIME:~3,2 ...

  9. 红米note3发热严重,小米真垃圾!

    红米note3全网通高配版,高通处理器骁龙650(MSM8956),夏天在有空调的房间,上网几分钟手机发烫,真垃圾! ROM已经是官方最新稳定版.MIUI8.5.2.0(LHNCNED) 红米NOTE ...

  10. [UE4]Widget Switcher:控件切换器

    一.Widget Switcher可以有很多子控件,但一次只会显示一个子控件.所有的子控件默认情况下都是充满整个Widget Switcher容器 二.Widget Switcher.Active W ...