1

This is my /etc/sudoers file edited with visudo, but I'm still asked to enter my password when doing sudo.

root ALL=(ALL) ALL
%admin  ALL=(ALL) NOPASSWD:ALL
petruza  ALL=(ALL) ALL
petruza  ALL=(ALL) NOPASSWD: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

I had this running in previous OS installs but now it doesn't work.

My main need for this is to automatically execute xampp at startup and not having it asking me for the password.

4
  • 3
    That's not a good idea to do as it opens a big security hole! Consider just allowing the individual app (smaller hole). What Mac OS version and how did you edit /etc/sudoers, with visudo? Sep 20, 2016 at 15:11
  • 1
    The permissions given in your sudoers file are complete overkill! Which xampp are you talking of? Automated start-up usually that can be done with a LaunchAgent without loosening any restrictions in sudoers!
    – klanomath
    Sep 20, 2016 at 15:12
  • @klanomath Ok! please tell me how!
    – Petruza
    Sep 20, 2016 at 15:15
  • @user3439894 How do I allow xampp individually? yes I edited it with visudo.
    – Petruza
    Sep 20, 2016 at 15:16

1 Answer 1

3

None of your modifications of the sudoers file is needed if you start xampp with a launch daemon:

  1. Create a file org.xampp.startup.plist in /Library/LaunchDaemons with sudo touch/nano ... and the following content:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
            <key>Label</key>
            <string>org.xampp.startup</string>
            <key>ProgramArguments</key>
            <array>
                    <string>/bin/bash</string>
                    <string>/Applications/XAMPP/xamppfiles/xampp</string>
                    <string>start</string>
            </array>
            <key>RunAtLoad</key>
            <true/>
            <key>StandardErrorPath</key>
            <string>/tmp/org.xampp.startup.stderr</string>
            <key>StandardOutPath</key>
            <string>/tmp/org.xampp.startup.stdout</string>
    </dict>
    </plist>
    

    If you installed XAMPP somewhere else please modify <string>/Applications/XAMPP/xamppfiles/xampp</string> accordingly.

  2. chown/chmod the file:

    sudo chown root:wheel /Library/LaunchDaemons/org.xampp.startup.plist
    sudo chmod 644 /Library/LaunchDaemons/org.xampp.startup.plist
    
  3. Load the daemon with:

    sudo launchctl load /Library/LaunchDaemons/org.xampp.startup.plist
    
  4. If everything runs well, you may remove the following part of the plist:

            <key>StandardErrorPath</key>
            <string>/tmp/org.xampp.startup.stderr</string>
            <key>StandardOutPath</key>
            <string>/tmp/org.xampp.startup.stdout</string>
    
  5. Restore the default sudoers file with visudo:

    ...
    root 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
    ...
    
1
  • Thanks, this works great, but only starts apache. MySQL won't. I added another Launch Daemon with xampp startmysql but won't work either. And stdout and stderr files have no hint about this.
    – Petruza
    Sep 28, 2016 at 14:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .