Added theself to /etc/sudoers but sudo still asks for password

sudo

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.

Best Answer

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
    ...