Dave's Brain

Browse - Programming Tips - How can I let a user on a webpage exec a command as another user?

Date: 2012apr20
OS: Linux

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:

Defaults:apache !requiretty %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.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.