ubuntu16.04 正确编辑 /etc/sudoers 文件,禁止普通用户使用超级权限

ubuntu16.04 正确编辑 /etc/sudoers 文件,禁止普通用户使用超级权限

/etc/sudoers 编辑权限问题

请先切换到超级用户(root),将 /etc/sudoers 修改为可编辑。

ls -lah /etc/sudoers
chmod 777 /etc/sudoers

/etc/sudoers 修改回只读模式。

chmod 440 /etc/sudoers
ls -lah /etc/sudoers

如何编辑 /etc/sudoers

User Privilege Lines

  • root ALL=(ALL:ALL) ALL
    The first field indicates the username that the rule will apply to (root).
  • demo ALL=(ALL:ALL) ALL
    The first “ALL” indicates that this rule applies to all hosts.
  • demo ALL=(ALL:ALL) ALL
    This “ALL” indicates that the root user can run commands as all users.
  • demo ALL=(ALL:ALL) ALL
    This “ALL” indicates that the root user can run commands as all groups.
  • demo ALL=(ALL:ALL) ALL
    The last “ALL” indicates these rules apply to all commands.
    This means that our root user can run any command using sudo, as long as they provide their password.

禁止普通用户使用 sudo, su 命令

这里约定普通用户的用户名是 www-data,其用户组只有 www-data
那么在 /etc/sudoers 中添加如下的规则,可以禁止用户使用 sudo 命令

www-data ALL=(www-data:www-data) /bin/*,/usr/bin/*,/sbin/*, /usr/sbin/*,!/usr/bin/sudo,!/bin/su,!/usr/bin/passwd,!/usr/bin/chattr -* /etc/sudoers

普通用户禁用 su 的话。这里需要注意的是 ubuntu 16.04 禁止普通用户使用 su 命令,需要修改 /etc/pam.d/su,找到类似 #auth required pam_wheel.so,取消其注释,并在其后添加允许使用 su 的用户组 group=sudo

最终的修改如下,修改后会立刻生效:

auth       required   pam_wheel.so group=sudo

可以不用在 /etc/login.defs 追加 SU_WHEEL_ONLY yes,如果追加,可能会报 SU Module Unknown Error。可能是由于 ubuntu 上没有 wheel 组,有可能会出现不兼容的情况,例如这位老哥 pam.d/su to restrict su access. SU Module Unknown Error

允许普通用户使用 sudo 命令

有如下几种方法,可以搜索其他博客进行参考:

  1. 把普通用户添加到 sudo 组别
  2. /etc/sudoers 添加规则,例如:
    www-data ALL=(ALL:ALL) ALL
    

为用户增加sudo权限(修改sudoers文件)

How To Edit the Sudoers File on Ubuntu and CentOS

【转】/etc/sudoers配置文件详解

公司Ubuntu设置员工sudo权限实例

Linux 禁止普通用户su切换root

Why is Debian not creating the ‘wheel’ group by default?

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值