sudo无密码配置没生效?也许是因为顺序

在Ubuntu上经常要用到sudo来运行一些系统相关的命令。每新开一次终端运行sudo就要重新输入一次密码,也是很烦。

用visudo修改sudoer的配置,在“用户特权”的root用户下写了用户名user1,并让它NOPASSWD

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
user1   ALL=(ALL:ALL) NOPASSWD:ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "@include" directives:

@includedir /etc/sudoers.d

但是很遗憾,这不生效。

原来是这个用户user1还在%admin和%sudo这个两个group里。

由此可见,如果将用户的定义写在这两个group前,某些设置可能不生效。

所以,我将定义NOPASSWD的位置写在了group之后。 It works!

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

user1   ALL=(ALL:ALL) NOPASSWD:ALL

# See sudoers(5) for more information on "@include" directives:

@includedir /etc/sudoers.d

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值