Ubuntu sudo nopasswd方法

发布时间 2023-08-29 22:58:24作者: 牧之丨

1 运行 visudo

2 假设用户名为yourname, 则在最后一行添加:


# 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
yourname ALL=(ALL) NOPASSWD: ALL
# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d


注意两点:

1 NOPASSWD: ALL 之间(红色部分)是有一个空格的。

2 一定要在最后一行添加,否则会被前面的(包括以%开始的那几句)覆盖。