I am assuming you are trying to give the www-data
user the ability to start and stop certain daemons, but that you don't want to change the user that the daemons run as. You can do this easily with sudo. First, run visudo
to safely edit /etc/sudoers
. Now, define a command alias that lists all the init scripts for the daemons you want the www-data
user to be able to control. The name of the alias is arbitrary. I don't know the exact names of the init scrips on debian. Overall, the line will looks something like
Cmnd_Alias WEBDAEMONS /etc/init.d/proftpd, /etc/init.d/mysql, /etc/init.d/samba
Next, authorize the www-data user to run those commands as root without a password on any server where this sudoers
file is installed. That should look like
www-data ALL = (root) NOPASSWD: WEBDAEMONS
Finally, save the file and exit visudo. At this point, you should be able to log in as the www-data
user and use sudo to run the commands you put in your command alias without needing to enter password. You could test this with something like the following:
billy@example:~$ sudo -i -u www-data bash
[sudo] password for billy:
www-data@example:~$ sudo /etc/init.d/proftpd restart
Restarting proftpd
www-data@example:~$ exit