Editing sudoers with a script
Posted on 2011-03-13
I'm creating a bash script that will prepare a vanilla ubuntu server for a custom web app. I need to add www-data to the sudoers file for later automation purposes.
I had hoped that the following would work but with hindsight, it's clear that doing it via sudo isn't going to work!
sudo chmod 640 /etc/sudoers
sudo echo "www-data ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
sudo chmod 440 /etc/sudoers
Can anyone suggest a way for me to automate the editing of sudoers? The less I need the user to perform manually, the better.
As a second request, can anyone suggest how to tighten the sudo entry for my needs? I have a perl script that is doing "sudo service myapp stop" so all www-data really needs is the ability to start and stop a single service.