LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Security (https://www.linuxquestions.org/questions/linux-security-4/)
-   -   ubuntu - running sudo shell script from php (https://www.linuxquestions.org/questions/linux-security-4/ubuntu-running-sudo-shell-script-from-php-560716/)

mitilma 06-10-2007 06:49 PM

ubuntu - running sudo shell script from php
 
Hi,

I am using Ubuntu Dapper and I want to run a command as root from a php script.

I try:

<?php
$output = shell_exec('sudo -u root -S ls < /home/mitilma/passfile');
echo "<pre>".$output."</pre>";
?>

However, ls command does not work in that case. It works without sudo in php, but with sudo, I cannot see any files listed. What is the problem? How can I solve it?

Thanks a lot..

fukawi2 06-10-2007 09:57 PM

Have you setup sudo for the Apache user and to not require a password from that user for that command?

mitilma 06-13-2007 06:22 PM

You said
"Have you setup sudo for the Apache user and to not require a password from that user for that command?"

How can I achieve it? I am new for Linux, and I really need help..

Thanks a lot..

fukawi2 06-14-2007 01:52 AM

As root, run 'visudo' and add something similar to these lines:
Code:

Cmnd_Alias      APACHECMDS =    /path/to/command/for/apache/user/to/run

apacheusername  ALL = APACHECMDS  NOPASSWD

If you need to allow it to run multiple commands, add a backslash to the Cmnd_Alias line like this:
Code:

Cmnd_Alias      APACHECMDS =    /path/to/command/for/apache/user/to/run \
                                  /path/to/second/command/for/apache/to/run

You can keep adding back slashes and more commands for as long as you like :)


All times are GMT -5. The time now is 01:43 AM.