LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-03-2008, 06:25 AM   #1
rejeep
Member
 
Registered: Mar 2007
Distribution: Gentoo
Posts: 49

Rep: Reputation: 15
Run as sudo from web browser?


Hi!

Since I don't know what is causing the problem I have I was unsure in which forum to post in. Please move if in wrong.

To my problem. I'm trying to run a script on my server from a web browser. The PHP-script I did for this looks like this (running on Apache):
Code:
<?php

echo "<pre>";
echo shell_exec("/path/to/my/script.sh");
echo "</pre>";

?>
And script.sh looks like this:
Code:
echo "password" | sudo -u user -S /usr/bin/mongrel_rails cluster::restart -C /etc/mongrel_cluster/enviroment.yml
And I guess (not sure) that the problem is that I run sudo. It works if I log in to the computer over SSH and run the script. But when executing it from the browser I'm not logged in as any user (right?), and therefore sudo cannot execute my script.

Could that be the source to my problem and how do I solve it?

Thanks!
 
Old 06-03-2008, 06:41 AM   #2
oskar
Senior Member
 
Registered: Feb 2006
Location: Austria
Distribution: Ubuntu 12.10
Posts: 1,142

Rep: Reputation: 49
Maybe

su -c 'command'

That also just executes one command, but it doesn't need sudo to be set up for the user.
 
Old 06-03-2008, 07:12 AM   #3
rejeep
Member
 
Registered: Mar 2007
Distribution: Gentoo
Posts: 49

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by oskar View Post
Maybe

su -c 'command'

That also just executes one command, but it doesn't need sudo to be set up for the user.
I don't think that you can pass the password to su in the same way you do with sudo. sudo -S tells sudo to read from the standard input instead of the terminal device.
 
Old 06-03-2008, 07:33 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,165
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
But when executing it from the browser I'm not logged in as any user (right?), and therefore sudo cannot execute my script.
You run the script as the user that runs apache. Run
Code:
ps -ef|grep httpd
to find that user (usually nobody or www-run) and put him in /etc/sudoers
 
Old 06-23-2008, 11:36 AM   #5
rejeep
Member
 
Registered: Mar 2007
Distribution: Gentoo
Posts: 49

Original Poster
Rep: Reputation: 15
The script was run as the user apache which had the SHELL-variable set to /sbin/nologin. I changed it to /bin/bash and it worked!

Thanks!
 
Old 06-23-2008, 01:05 PM   #6
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Quote:
Originally Posted by rejeep View Post
The script was run as the user apache which had the SHELL-variable set to /sbin/nologin. I changed it to /bin/bash and it worked!

Thanks!
I could probably list a millions reasons why apache should not have a valid shell account. Huge security risk is the number one reason.
 
Old 06-24-2008, 02:07 AM   #7
rejeep
Member
 
Registered: Mar 2007
Distribution: Gentoo
Posts: 49

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by trickykid View Post
I could probably list a millions reasons why apache should not have a valid shell account. Huge security risk is the number one reason.
Of course there's a reason to why apache doesn't have a shell. But for now it's works, and thats the most important.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can ping web page from telnet, but can't open it in web browser a.ilic Linux - Networking 1 04-01-2008 10:29 AM
How do I log into file browser with sudo? Fasn8n Ubuntu 2 03-03-2006 02:51 PM
What must I do when I want to run PHP on Web browser ? manhcuong Linux - Software 1 12-06-2005 03:25 AM
Looking for a small web browser that lets me run webmin on a p1 machine Neoxeekhrobe Linux - Software 4 10-14-2005 12:50 PM
browser plugin for Konqueror web browser (linspire) Tracianddwayne Linux - Newbie 1 01-01-2005 02:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:01 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