Run sudo command without a password

Run sudo command without a password

  1. Open /etc/sudoers with visudo editor, as if straight away edit /etc/sudoers file with text editor, it won't validate the syntax.

    sudo visudo
  2. Append this line username ALL=(ALL:ALL) NOPASSWD:ALL at the end of the /etc/sudoers file

    /etc/sudoers
    # 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
    kc      ALL=(ALL:ALL) NOPASSWD:ALL
  3. Open a new terminal window and test the command with root privileges

    sudo apt-get update