Securely executing system commands as sudo from PHP
Posted
by
Aydin Hassan
on Server Fault
See other posts from Server Fault
or by Aydin Hassan
Published on 2014-08-18T20:00:08Z
Indexed on
2014/08/18
22:23 UTC
Read the original article
Hit count: 369
Is it possible?
I have written a command line tool in PHP for creating new environments for our company. It creates system users, directories, databases, VHosts and restarts apache, amongst other things. These commands require sudo
privileges. I thought it might be a nice idea to have a web-interface for it, to make it easier for other non-developers to use. The web app would be behind authentication.
When running from the command line I just run sudo tool.php
, obviously I can't do this from a web app.
How could I do this securely? Giving the apache user sudo access seems silly, as this would means all sites hosted on the box (eg all our environments) would have sudo access. Is it possible to make this tool run under a different user? this user could have sudo privileges for only the commands I need?
How do things like plesk and cPanel do this?
Any thoughts?
© Server Fault or respective owner