0

I don't think this is a duplicate because

the main purpose of this post is to find a way to allow admin Mac OS X user to run specific sudo command without having to enter password.

I'm on a Mac OS X. I ran whoami I see bheng and I am admin.

I then open this file /etc/sudoers sudo visudo

In User privilege specification section, I added

bheng ALL=(ALL) ALL

like this

##                                                                                                                                                                     
## 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 += "BLOCKSIZE"                                                                                                                                    
Defaults    env_keep += "COLORFGBG COLORTERM"                                                                                                                          
Defaults    env_keep += "__CF_USER_TEXT_ENCODING"                                                                                                                      
Defaults    env_keep += "CHARSET LANG LANGUAGE LC_ALL LC_COLLATE LC_CTYPE"                                                                                             
Defaults    env_keep += "LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME"                                                                                                   
Defaults    env_keep += "LINES COLUMNS"                                                                                                                                
Defaults    env_keep += "LSCOLORS"                                                                                                                                     
Defaults    env_keep += "SSH_AUTH_SOCK"                                                                                                                                
Defaults    env_keep += "TZ"                                                                                                                                           
Defaults    env_keep += "DISPLAY XAUTHORIZATION XAUTHORITY"                                                                                                            
Defaults    env_keep += "EDITOR VISUAL"                                                                                                                                
Defaults    env_keep += "HOME MAIL"                                                                                                                                    
                                                                                                                                                                       
Defaults    lecture_file = "/etc/sudo_lecture"                                                                                                                         
                                                                                                                                                                       
##                                                                                                                                                                     
## 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                                                                                                                                     
~   

I still seem to not able to run sudo command, example testing.sh

sudo echo "
 
<VirtualHost *:80 >
    ServerName qwerty.test
    VirtualDocumentRoot "/Users/bheng/Sites/laravel/qwerty/public"
    UseCanonicalName Off
</VirtualHost>
 
" >> /etc/apache2/extra/httpd-vhosts.conf

sudo apachectl -k restart

I kept getting when run sh testing.sh

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

How would one go about allowing this?

Update

I've tried this updated code

sudo echo "

<VirtualHost *:80 >
    ServerName qwerty.test
    VirtualDocumentRoot "/Users/bheng/Sites/laravel/qwerty/public"
    UseCanonicalName Off
</VirtualHost>

" | sudo tee --append /etc/apache2/extra/httpd-vhosts.conf

apachectl -k restart

Try running it

⚡️  laravel  sh testing.sh 
Password:

I prompt me for password again ?

Community
  • 1
  • 1
code-8
  • 49,286
  • 91
  • 294
  • 502
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/190064/discussion-on-question-by-kyo-how-can-i-allow-admin-mac-os-user-to-run-specific). – Bhargav Rao Mar 15 '19 at 03:12

0 Answers0