LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 06-10-2007, 06:49 PM   #1
mitilma
LQ Newbie
 
Registered: Jun 2007
Posts: 4

Rep: Reputation: 0
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..
 
Old 06-10-2007, 09:57 PM   #2
fukawi2
Member
 
Registered: Oct 2006
Location: Melbourne, Australia
Distribution: ArchLinux, ArchServer, Fedora, CentOS
Posts: 449

Rep: Reputation: 34
Have you setup sudo for the Apache user and to not require a password from that user for that command?
 
Old 06-13-2007, 06:22 PM   #3
mitilma
LQ Newbie
 
Registered: Jun 2007
Posts: 4

Original Poster
Rep: Reputation: 0
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..
 
Old 06-14-2007, 01:52 AM   #4
fukawi2
Member
 
Registered: Oct 2006
Location: Melbourne, Australia
Distribution: ArchLinux, ArchServer, Fedora, CentOS
Posts: 449

Rep: Reputation: 34
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

Last edited by fukawi2; 06-14-2007 at 01:53 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running shell script with PHP in Apache mr_scary Programming 2 10-20-2006 04:17 PM
php script & sudo rblampain Programming 3 05-13-2006 08:03 PM
sudo don't work in php script maxabbr Linux - General 2 05-05-2006 11:22 AM
allow sudo for www user to run root shell script cccc *BSD 12 07-23-2005 03:48 PM
howto start vpnclient with php script and sudo ? cccc Programming 1 01-12-2004 11:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 07:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration