1

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.

1 Answer 1

0

You should have the root script "pull" from the regular rather than having the latter "push" to the former. As an illustrative example:

  1. Create a cron job that checks for a list of folders to be created in a text file
  2. Have the lighttpd user script append the desired folder to that text file

You can do this more elegantly with a queuing/messaging system, but that's up to you.

2
  • Inotify tools could also be used to get instant response from backend script Commented Oct 19, 2016 at 21:26
  • 1
    Andre Terra thanks for the suggestion on how to approach the problem. Now that you mention it I cannot look at the problem in another way. A cron job could definitely work, but as you stated it will not be a very elegant solution. I will try to use Inotify (thanks @Sampo Sarrala) as it seems easier to set up than the queuing/messaging system. I'll let you guys know the result as soon as possible.
    – Hugo Paiva
    Commented Oct 20, 2016 at 16:42

You must log in to answer this question.

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