Re: Execute command line as a different user

From: Date: Tue, 01 Jul 2008 18:07:45 +0000
Subject: Re: Execute command line as a different user
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-276190@lists.php.net to get a copy of this message
Shawn McKenzie wrote:
Matt palermo wrote:
My PHP is running as a user with limited rights. I'd like to execute a command line as a different user. I'm trying to delete a file and the PHP user doesn't have access to do this. I know the username and password for the admin user that has rights to delete a file. Is there a command I can use to make PHP run a delete command as the admin user? If so, how can I do this? Thanks, Matt
There are several ways on *nix systems. I would probably write a shell script to do the deletions and setuid of the script to root or a user with rights to delete the files. Then just exec() the shell script. On winbloze you can use the runas command. -Shawn
Actually, a quick search shows that many *nix may not let you setuid on a executable script, so sudo would be an approach. You should be able to setup the apache user in the sudoers file so that it can only run a very specif command, such as 'rm /path/to/file/to/delete'. Then just use that: exec('sudo rm /path/to/file/to/delete'); -Shawn

« previous php.general (#276190) next »