Is it possible to make the web server user, lighttpd
in my case, to trigger a specific script that needs to run with sudo
permissions?
I only want the lighttpd
user to be able to trigger that one script with sudo
permissions.
The script, let's call it createFolder.sh
, creates a folder from a template in the upper level of a share. The users have no writing permissions on the upper level of the share but should have writing permission in the newly created folder structure. Therefore, the script sets up the right permissions on the subfolders and that's where the need of using sudo
comes from (chown
, chmod
and setfacl
).
The reason I would like to use a web interface for it is so the users can insert the data for the folder name and settings that will define the exact folder structure.
I thought it would be as simple as to add an entry in /etc/sudoers
to allow the lighttpd
user to run the createFolder.sh
with no password. Seems like I was wrong as I get the following error:
sudo: unable to mkdir /var/db/sudo/lighttpd: Permission denied
We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things:
1) Respect the privacy of others.
2) Think before you type.
3) With great power comes great responsibility.sudo: no tty present and no askpass program specified
If it was possible to set the script to always run as a user with the right permissions it would sort it out but I couldn't find how to do it or if it is possible.
As a side note, I have learned Linux on my own and even if I feel confident in my abilities I am no specialist and am always looking to improve.
I am running a CentOS 7 box.
EDIT: I have solved the problem by using inotify to trigger my createFolder.sh
script when a text file is modified. See correct answer and its comments. Thanks for pointing me in the right direction guys.