enable NOPASSWD for yourself

I have some bash scripts which I manually run a lot and they need to run with sudo. I also don’t want to be prompted for any password. Here is the solution.

  1. Edit the /etc/sudoers:
    $ sudo vi /etc/sudoers
  2. Add a new entry at the last (USERNAME is your account name).
    # 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
    USERNAME        ALL=(ALL:ALL)   NOPASSWD:ALL
    
    # See sudoers(5) for more information on "#include" directives:
    
    #includedir /etc/sudoers.d
    
  3. Restart the sudo service.
    $ sudo service sudo restart
  4. Logout then login again. You won’t be prompted for the password anymore.
%d bloggers like this: