在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