Notice#
The commands mentioned next may require
root
permission.
Option. 1: add config directly#
Edit config file /etc/sudoers
(or you can just run command “visudo”):
1visudo
1#
2# This file MUST be edited with the 'visudo' command as root.
3#
4# Please consider adding local content in /etc/sudoers.d/ instead of
5# directly modifying this file.
6#
7# See the man page for details on how to write a sudoers file.
8#
9Defaults env_reset
10Defaults mail_badpass
11Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
12
13# Host alias specification
14
15# User alias specification
16
17# Cmnd alias specification
18
19# User privilege specification
20root ALL=(ALL:ALL) ALL
21
22# Members of the admin group may gain root privileges
23%admin ALL=(ALL) ALL
24
25# Allow members of group sudo to execute any command
26%sudo ALL=(ALL:ALL) ALL
27
28# See sudoers(5) for more information on "#include" directives:
29
30#includedir /etc/sudoers.d
Add the following config to last line (at least, it should be put after %sudo ALL=(ALL:ALL) ALL
):
1alpaca ALL=(ALL:ALL) NOPASSWD:ALL
Don’t forget to change the username
alpaca
to name of you own user.
(For saving and leaving the editing mode, press ctrl
+x
, then press y
.)
Option. 2: create a config file on /etc/sudoers.d/#
First step is same, Edit config file /etc/sudoers
(or you can just run command “visudo”):
1visudo
And uncomment “#includedir /etc/sudoers.d”:
1#includedir /etc/sudoers.d
1includedir /etc/sudoers.d
(For saving and leaving the editing mode, press ctrl
+x
, then press y
.)
Then create a file on /etc/sudoers.d/
, for example filename “alpaca”:
1touch /etc/sudoers.d/alpaca
Also write the config into the file:
1alpaca ALL=(ALL:ALL) NOPASSWD:ALL
Don’t forget to change the username
alpaca
to name of you own user.
References#
- 《command line - Execute sudo without Password? - Ask Ubuntu》https://askubuntu.com/questions/147241/execute-sudo-without-password