Sudo Without Password

As you can see from the graphic above using sudo command makes the system obey any given order.

Sometimes can be exhausting having to use sudo all the time to complete tasks. For instance, I use Apache for web development and to start the daemon on port 80 one needs to run it as root in order to Apache to be able to bind that port (in fact any port below 1024).

Beware
(of the monster in this closet)
This little tweak can create high security risks! Use with caution.

We need to edit the /etc/sudoers file and set the user and the binary that will be allowed to run as root without authentication. Open a terminal and type:

sudo nano /etc/sudoers

Find the section "User privilege specification" and below the last line of it insert your rules.

Before Editing:

The sudoers file will look like this:
 ##
    ## User privilege specification
   ##
    root ALL=(ALL) ALL
    %admin  ALL=(ALL) ALL
The Fail - Asking for password:
   mteam7 [~] $ sudo /usr/local/bin/apachectl start
    Password:

After Editing:

The sudoers file will look like this:
  ##
    ## User privilege specification
   ##
    root ALL=(ALL) ALL
    %admin  ALL=(ALL) ALL
 mteam7 ALL=(ALL) NOPASSWD:/usr/bin/dscacheutil
    mteam7 ALL=(ALL) NOPASSWD:/usr/local/bin/mkdocs
   mteam7 ALL=(ALL) NOPASSWD:/usr/local/bin/nginxctl
 mteam7 ALL=(ALL) NOPASSWD:/usr/local/bin/apachectl
The Win - No password:
   mteam7 [~] $ sudo /usr/local/bin/apachectl start

No password question... it just ran!

Explanation:

   USER    |  TERMINAL | ACTING AS |  COMMAND
   ---------------------------------------------------------------------
 mteam7        ALL=       (ALL)      NOPASSWD:/usr/local/bin/apachectl

Edit the sudoers file as your needs require and press CTRL+O to write the file. CTRL+X to quit nano.

With the setup above I can now run any of these commands with sudo without having to type an admin password. Very handy!

{{ message }}

{{ 'Comments are closed.' | trans }}