Programming Tips - How can I let a user on a webpage exec a command as another user?
Q. How can I let a user on a webpage exec a command as another user?
(The webserver runs as user "apache" but I need to do a command
as a different user)
A. There are several different ways to do this. Here's one that is
pretty nice. Let's say you what your users to be able to run command
/usr/lib/mailman/bin/inject as user mailman via a php page you made.
Add this to your /etc/sudoers file:
%apache ALL=(mailman) NOPASSWD: /usr/lib/mailman/bin/inject
Then your php script can do:
system("sudo -u mailman /usr/lib/mailman/bin/inject ...");
As you can see, we are using the powerful sudo command to make this happen.