By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,045 Members | 1,139 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,045 IT Pros & Developers. It's quick & easy.

Php-html and apache user

P: n/a
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

Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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" <so******@cs.unibo.it> wrote in message
news:Pi**************************************@piso lo.cs.unibo.it...
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

Jul 17 '05 #2

P: n/a
On Mon, 27 Oct 2003 20:00:38 +0100, Lorenza Soverini wrote:
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.

<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/

Jul 17 '05 #3

P: n/a
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


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/


Jul 17 '05 #4

P: n/a
> 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...


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/

Jul 17 '05 #5

P: n/a
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:
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" <so******@cs.unibo.it> wrote in message
news:Pi**************************************@piso lo.cs.unibo.it...
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



Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.