title: How can I allow admin Mac OS user to run specific sudo command without having to enter password?
body: <p>I don't think this is a duplicate because</p>
  <blockquote>
  <p>the main purpose of this post is to find a way to allow admin Mac OS X user to run specific <code>sudo</code> command without having to enter password.</p>
  </blockquote>
  <p>I'm on a Mac OS X. I ran <code>whoami</code> I see <code>bheng</code> and I am admin.</p>
  <p>I then open this file <strong>/etc/sudoers</strong> <code>sudo visudo</code></p>
  <p>In User privilege specification section, I  added</p>
  <blockquote>
  <p>bheng ALL=(ALL) ALL</p>
  </blockquote>
  <p>like this</p>
  <pre><code>##                                                                                                                                                                     
  ## Groups of users.  These may consist of user names, uids, Unix groups,                                                                                               
  ## or netgroups.                                                                                                                                                       
  # User_Alias    ADMINS = millert, dowdy, mikef                                                                                                                         
                                                                                                                                                                         
  ##                                                                                                                                                                     
  ## Cmnd alias specification                                                                                                                                            
  ##                                                                                                                                                                     
  ## Groups of commands.  Often used to group related commands together.                                                                                                 
  # Cmnd_Alias    PROCESSES = /usr/bin/nice, /bin/kill, /usr/bin/renice, \                                                                                               
  #                           /usr/bin/pkill, /usr/bin/top                                                                                                               
                                                                                                                                                                         
  ##                                                                                                                                                                     
  ## Defaults specification                                                                                                                                              
  ##                                                                                                                                                                     
                                                                                                                                                                         
  Defaults    env_reset                                                                                                                                                  
  Defaults    env_keep += &quot;BLOCKSIZE&quot;                                                                                                                                    
  Defaults    env_keep += &quot;COLORFGBG COLORTERM&quot;                                                                                                                          
  Defaults    env_keep += &quot;__CF_USER_TEXT_ENCODING&quot;                                                                                                                      
  Defaults    env_keep += &quot;CHARSET LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE&quot;                                                                                             
  Defaults    env_keep += &quot;LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME&quot;                                                                                                   
  Defaults    env_keep += &quot;LINES COLUMNS&quot;                                                                                                                                
  Defaults    env_keep += &quot;LSCOLORS&quot;                                                                                                                                     
  Defaults    env_keep += &quot;SSH_AUTH_SOCK&quot;                                                                                                                                
  Defaults    env_keep += &quot;TZ&quot;                                                                                                                                           
  Defaults    env_keep += &quot;DISPLAY XAUTHORIZATION XAUTHORITY&quot;                                                                                                            
  Defaults    env_keep += &quot;EDITOR VISUAL&quot;                                                                                                                                
  Defaults    env_keep += &quot;HOME MAIL&quot;                                                                                                                                    
                                                                                                                                                                         
  Defaults    lecture_file = &quot;/etc/sudo_lecture&quot;                                                                                                                         
                                                                                                                                                                         
  ##                                                                                                                                                                     
  ## Runas alias specification                                                                                                                                           
  ##                                                                                                                                                                     
                                                                                                                                                                         
  ##                                                                                                                                                                     
  ## User privilege specification                                                                                                                                        
  ##                                                                                                                                                                     
  root ALL=(ALL) ALL                                                                                                                                                     
  bheng ALL=(ALL) ALL                                                                                                                                                    
                                                                                                                                                                         
  %admin  ALL=(ALL) ALL                                                                                                                                                  
                                                                                                                                                                         
                                                                                                                                                                         
  ## Uncomment to allow members of group wheel to execute any command                                                                                                    
  # %wheel ALL=(ALL) ALL                                                                                                                                                 
                                                                                                                                                                         
  ## Same thing without a password                                                                                                                                       
  # %wheel ALL=(ALL) NOPASSWD: ALL                                                                                                                                       
                                                                                                                                                                         
  ## Uncomment to allow members of group sudo to execute any command                                                                                                     
  # %sudo ALL=(ALL) ALL                                                                                                                                                  
                                                                                                                                                                         
  ## Uncomment to allow any user to run sudo if they know the password                                                                                                   
  ## of the user they are running the command as (root by default).                                                                                                      
  # Defaults targetpw  # Ask for the password of the target user                                                                                                         
  # ALL ALL=(ALL) ALL  # WARNING: only use this together with 'Defaults targetpw'                                                                                        
                                                                                                                                                                         
  ## Read drop-in files from /private/etc/sudoers.d                                                                                                                      
  ## (the '#' here does not indicate a comment)                                                                                                                          
  #includedir /private/etc/sudoers.d                                                                                                                                     
  ~   
  </code></pre>
  <p>I still seem to not able to run sudo command, example <code>testing.sh</code></p>
  <pre><code>sudo echo &quot;
   
  &lt;VirtualHost *:80 &gt;
      ServerName qwerty.test
      VirtualDocumentRoot &quot;/Users/bheng/Sites/laravel/qwerty/public&quot;
      UseCanonicalName Off
  &lt;/VirtualHost&gt;
   
  &quot; &gt;&gt; /etc/apache2/extra/httpd-vhosts.conf
  
  sudo apachectl -k restart
  </code></pre>
  <p>I kept getting when run <code>sh testing.sh</code></p>
  <pre><code>testing.sh: line 1: /etc/apache2/extra/httpd-vhosts.conf: Permission denied
  httpd not running, trying to start
  (48)Address already in use: AH00072: make_sock: could not bind to address [::]:80
  (48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
  no listening sockets available, shutting down
  AH00015: Unable to open logs
  </code></pre>
  <p>How would one go about allowing this?</p>
  <h1>Update</h1>
  <p>I've tried this updated code</p>
  <pre><code>sudo echo &quot;
  
  &lt;VirtualHost *:80 &gt;
      ServerName qwerty.test
      VirtualDocumentRoot &quot;/Users/bheng/Sites/laravel/qwerty/public&quot;
      UseCanonicalName Off
  &lt;/VirtualHost&gt;
  
  &quot; | sudo tee --append /etc/apache2/extra/httpd-vhosts.conf
  
  apachectl -k restart
  </code></pre>
  <p>Try running it</p>
  <pre><code>⚡️  laravel  sh testing.sh 
  Password:
  </code></pre>
  <p>I prompt me for password again ? </p>