Sudo without password
How to run sudo command without prompting password:
Create backup of
/etc/sudoers:$ sudo cp /etc/sudoers /etc/sudoers.bakThen, using nano/vi to edit the
/etc/sudoersfile.$ sudo visudoBy default visudo using
vieditor, but if you want to usenano(for example).It will show similar like this and
enteryour preferred editor.$ sudo update-alternatives --config editor There are 4 choices for the alternative editor (providing /usr/bin/editor). Selection Path Priority Status ------------------------------------------------------------ * 0 /bin/nano 40 auto mode 1 /bin/ed -100 manual mode 2 /bin/nano 40 manual mode 3 /usr/bin/vim.basic 30 manual mode 4 /usr/bin/vim.tiny 15 manual mode Press <enter> to keep the current choice[*], or type selection number:Add or Edit your
userto add theNO PASSWDprivilege. It will show similar like this.# This file MUST be edited with the 'visudo' command as root. # # Please consider adding local content in /etc/sudoers.d/ instead of # directly modifying this file. # # See the man page for details on how to write a sudoers file. # Defaults env_reset Defaults mail_badpass Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin" # Host alias specification # User alias specification # Cmnd alias specification # 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 # See sudoers(5) for more information on "#include" directives: #includedir /etc/sudoers.d $USER ALL=(ALL) NOPASSWD: ALL # $USER is your user in Unix/Linux host.To give it a try, you can save the new
/etc/sudoersfile and do:$ sudo su root@your-pc-name:/home/user#