This is for the one who is repeatedly typing his/her password in his *nix system. This tip in a personal pc/system is execellent but when used in systems accessible by others is potentially dangerous and I seriously don't recommend this to be used in such environments! If doing so, resulted in something terrible, I am not responsible! Thank you!


A little Story...

Atleast, once in the history of using *nix as OS, we would have come across the situation, where we would have typed a command in shell, and the shell spits out a nasty permission denied error. We immediately, add a sudo and re-execute the same command. Now, shell asks for the user's password. For this, shell we don't have to type the password anymore, but I closed the shell and opened a new shell, and type sudo {command}, we must type the password to validate my presence again.....

### Let's see How to stop retyping the password after login: There are two ways of doing it, - a risky way of adding things straight to sudoers file - or a add a file to a particular folder and it will be picked up by sudoers file

I will be elaborating just the second way, because this doesn't involve me directly messing with the defaults and I feel it sane, safe & sound.

View the Last Line in the /etc/sudoers file:

# 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

The last line #includedir /etc/sudoers.d is an actual directory which will be included automatically by this file. Let's add ourself to sudoers, so we can stop typing password for sudo commands:

  • Create a file with the username in /etc/sudoers.d, don't forget to use sudo when creating the file.
  • Now add the following to the file: Substitute {username} with your system's username

    {username} ALL=(ALL:ALL) NOPASSWD: ALL
    
  • Save the file and do a restart for the sudo service or do a full system restart, if that doesn't help.

Now, if you open a shell and type sudo commands, you will not be prompted for passwords.

Note: Be careful, because we are messing with sudo services, this might potentially be dangerous.