快轉到主要內容

How to run "sudo" command without typing password?

·289 字
Computer-Science Ubuntu
目錄
Make your username able to run "sudo" without password.

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
#

Alpaca
作者
Alpaca
No one can stop my feet.

相關文章

Change username and home folder in ubuntu
·189 字
Computer-Science Ubuntu
Ubuntu Server Auto Login TTY when Start up
·443 字
Computer-Science Ubuntu
Ubuntu "Crontab" 工作排程
·1115 字
Computer-Science Ubuntu
How to set timezone on ubuntu?
·183 字
Computer-Science Ubuntu
Ubuntu 更改家目錄語言
·574 字
Computer-Science Ubuntu

簡單幾步變更家目錄的語言

Ubuntu 更換 /Home 到新硬碟
·1364 字
Computer-Science Ubuntu Disk

如果發現當初掛載好的空間不夠用了,那麼擴充硬碟上去,然後照著步驟一步步的將檔案們搬家吧。