Connecting Tech Pros Worldwide Help | Site Map

Php-html and apache user

Lorenza Soverini
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi,
I'm a beginner with php and I've a problem using it from a web page.
I explain:
I need to establish an ssh connection from a web page. I've used
ssh.keygen for the authentication, that means that the user "lorenza" can
login without interactive ssh.
I've noticed that when I call a php script from a web page, it will be
executed from the "apache user".
now, the problem is that the ssh connection isn't established because the
user apache is not authorized and I've no possibility to authorize him
(administration problem).

anyone knows how can I establish an ssh connection to a remote host where
only the ssh port is opened, using php or something else, and
authenticating with a user different from apache??
Lorenza

Brian
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Php-html and apache user


So you want a php script to launch an shell command, that shell command
being 'ssh', is that correct?

The apache launched process will always be owned by the apache process
unless you setuid, or use sudo to allow it to launch processes as other
users. I don't reccomend this.

You can call ssh differently. "/sbin/ssh -lusername hostname", I imagine
your trying to use your keys, correct? specify the keys also.
"/sbin/ssh -lusername -f identity hostname".

Now calling it from PHP all depends on what you want to do with it. You're
not going to be able to do interactive ssh sessions, so yo have to deciede
if you want to capture the output of your command, or just execute the
command and ignore the output. You can simulate interactivity via
http://us4.php.net/manual/en/function.proc-open.php

<?php
define('SSHCMD', '/sbin/sssh -l harrysacks -f
/home/harrysacks/.ssh/identity scrotum.org "/bin/ls /etc/hack"');
//Use popen, or backticks, your choice
$ssh = popen(SSHCMD, "r");
print fread($ssh, 4096);
pclose($ssh);
unset($ssh);
//or
$ssh = `SSHCMD`;
print $ssh;
?>

Good luck.

"Lorenza Soverini" <soverini@cs.unibo.it> wrote in message
news:Pine.LNX.4.21.0310271956000.31393-100000@pisolo.cs.unibo.it...[color=blue]
> Hi,
> I'm a beginner with php and I've a problem using it from a web page.
> I explain:
> I need to establish an ssh connection from a web page. I've used
> ssh.keygen for the authentication, that means that the user "lorenza" can
> login without interactive ssh.
> I've noticed that when I call a php script from a web page, it will be
> executed from the "apache user".
> now, the problem is that the ssh connection isn't established because the
> user apache is not authorized and I've no possibility to authorize him
> (administration problem).
>
> anyone knows how can I establish an ssh connection to a remote host where
> only the ssh port is opened, using php or something else, and
> authenticating with a user different from apache??
> Lorenza
>[/color]


Jeffrey Silverman
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Php-html and apache user


On Mon, 27 Oct 2003 20:00:38 +0100, Lorenza Soverini wrote:
[color=blue]
> Hi,
> I'm a beginner with php and I've a problem using it from a web page.
> I explain:
> I need to establish an ssh connection from a web page. I've used
> ssh.keygen for the authentication, that means that the user "lorenza" can
> login without interactive ssh.[/color]
<snip!>

Question is, why do you need to do this? There is more than one way to
solve any programming problem and there may be a solution that works
better.
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/

Lorenza Soverini
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Php-html and apache user


Answer is:
I thought that php was a good way to do it... and I don't know another way
to do it...
any suggestion will be well accepted...
Lorenza

[color=blue]
>
> Question is, why do you need to do this? There is more than one way to
> solve any programming problem and there may be a solution that works
> better.
> --
> Jeffrey D. Silverman | jeffrey AT jhu DOT edu
> Johns Hopkins University | Baltimore, MD
> Website | http://www.wse.jhu.edu/newtnotes/
>
>[/color]

Brian
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Php-html and apache user


> I thought that php was a good way to do it... and I don't know another way
to do it...[color=blue]
> any suggestion will be well accepted...[/color]

Can you walk us thru what the object of the project is?

Expect might be the way to go if your trying to script terminal
interactions.
http://expect.nist.gov/



Lorenza Soverini
Guest
 
Posts: n/a
#6: Jul 17 '05

re: Php-html and apache user


Hi,
first of all thanx for your answer...
I've tried to do what you said, I've seen, using Iptraf, that something
works, but not properly..
Without using -i identity it doesn't work at all, adding that it trys to
connect but the connaction isn't established.
I've tried exactly the code you write in that mail but I receive any
result.

The thing I need to do is connecting to a remote machine andh copy some
files from it...
I've even tried scp but the problem is the same, it cannot establish the
connection.

....and I really don't know why...
Lorenza

On Mon, 27 Oct 2003, it was written:
[color=blue]
> So you want a php script to launch an shell command, that shell command
> being 'ssh', is that correct?
>
> The apache launched process will always be owned by the apache process
> unless you setuid, or use sudo to allow it to launch processes as other
> users. I don't reccomend this.
>
> You can call ssh differently. "/sbin/ssh -lusername hostname", I imagine
> your trying to use your keys, correct? specify the keys also.
> "/sbin/ssh -lusername -f identity hostname".
>
> Now calling it from PHP all depends on what you want to do with it. You're
> not going to be able to do interactive ssh sessions, so yo have to deciede
> if you want to capture the output of your command, or just execute the
> command and ignore the output. You can simulate interactivity via
> http://us4.php.net/manual/en/function.proc-open.php
>
> <?php
> define('SSHCMD', '/sbin/sssh -l harrysacks -f
> /home/harrysacks/.ssh/identity scrotum.org "/bin/ls /etc/hack"');
> //Use popen, or backticks, your choice
> $ssh = popen(SSHCMD, "r");
> print fread($ssh, 4096);
> pclose($ssh);
> unset($ssh);
> //or
> $ssh = `SSHCMD`;
> print $ssh;
> ?>
>
> Good luck.
>
> "Lorenza Soverini" <soverini@cs.unibo.it> wrote in message
> news:Pine.LNX.4.21.0310271956000.31393-100000@pisolo.cs.unibo.it...[color=green]
> > Hi,
> > I'm a beginner with php and I've a problem using it from a web page.
> > I explain:
> > I need to establish an ssh connection from a web page. I've used
> > ssh.keygen for the authentication, that means that the user "lorenza" can
> > login without interactive ssh.
> > I've noticed that when I call a php script from a web page, it will be
> > executed from the "apache user".
> > now, the problem is that the ssh connection isn't established because the
> > user apache is not authorized and I've no possibility to authorize him
> > (administration problem).
> >
> > anyone knows how can I establish an ssh connection to a remote host where
> > only the ssh port is opened, using php or something else, and
> > authenticating with a user different from apache??
> > Lorenza
> >[/color]
>
>
>[/color]

Closed Thread