You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by je...@Keane.com on 2004/03/16 22:13:07 UTC

[users@httpd] calling ssh/scp shell processes from within apache

I realize this is not solely an Apache question, i'm also posting to a php
list, and didn't want to cross post.

I have a page, written in PHP that calls three shell commands.  I'm calling
scp, then ssh and scp again.  I am using full paths when calling these
programs, i.e. /usr/bin/scp, /usr/bin/ssh.  The script works fine if
executed from the command line, as the user Apache runs as.  When i try to
execute similar code from a web browser being served up by Apache, none of
the commands seem to execute.

I would assume this has something to do with the environment the web
process runs in??  The ssh/scp connection autheticates with public key pair
authentication, which may not be allowed in this context.  I think/pretty
sure its getting challenged for the passphrase.
but, i'll send this anyway...just in case anyone has any insight/expierence
with this.

Server in question is Solaris9 with Apache 1.3.9/PHP 4.3.3

TIA.....Sorry for the slightly off topic post.
Jeff





---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] calling ssh/scp shell processes from within apache

Posted by Henry <he...@ix.netcom.com>.
I'm doing the exact same thing... and here's what a friend of mine told me to do, and it works.  

---------
Both scp and sftp use the same authentication mechanisms as ssh. They'll 
prompt for a password if they can't authenticate some other way; you 
could probably watch for the prompt in PHP, but I'd recommend running 
"ssh-keygen -t dsa" as the web server user, in that user's $HOME, to 
create a keypair with no passphrase. Then copy the public key into the 
destination machine's $HOME/.ssh/authorized_keys file with mode 600, and test 
that you can ssh as the web server user to the destination machine 
without typing anything.

Once that works, you should be able to call scp from system() to copy 
your files over.
---------

-Hank


----- Original Message ----- 
From: <je...@Keane.com>
To: <us...@httpd.apache.org>
Sent: Tuesday, March 16, 2004 4:13 PM
Subject: [users@httpd] calling ssh/scp shell processes from within apache


> 
> I realize this is not solely an Apache question, i'm also posting to a php
> list, and didn't want to cross post.
> 
> I have a page, written in PHP that calls three shell commands.  I'm calling
> scp, then ssh and scp again.  I am using full paths when calling these
> programs, i.e. /usr/bin/scp, /usr/bin/ssh.  The script works fine if
> executed from the command line, as the user Apache runs as.  When i try to
> execute similar code from a web browser being served up by Apache, none of
> the commands seem to execute.
> 
> I would assume this has something to do with the environment the web
> process runs in??  The ssh/scp connection autheticates with public key pair
> authentication, which may not be allowed in this context.  I think/pretty
> sure its getting challenged for the passphrase.
> but, i'll send this anyway...just in case anyone has any insight/expierence
> with this.
> 
> Server in question is Solaris9 with Apache 1.3.9/PHP 4.3.3
> 
> TIA.....Sorry for the slightly off topic post.
> Jeff
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
> 
> 

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


RE: [users@httpd] calling ssh/scp shell processes from within apache

Posted by Ben Yau <by...@cardcommerce.com>.

> I realize this is not solely an Apache question, i'm also posting to a php
> list, and didn't want to cross post.
>
> I have a page, written in PHP that calls three shell commands.
> I'm calling
> scp, then ssh and scp again.  I am using full paths when calling these
> programs, i.e. /usr/bin/scp, /usr/bin/ssh.  The script works fine if
> executed from the command line, as the user Apache runs as.  When i try to
> execute similar code from a web browser being served up by Apache, none of
> the commands seem to execute.
>
> I would assume this has something to do with the environment the web
> process runs in??  The ssh/scp connection autheticates with
> public key pair
> authentication, which may not be allowed in this context.  I think/pretty
> sure its getting challenged for the passphrase.
> but, i'll send this anyway...just in case anyone has any
> insight/expierence
> with this.
>

Just curious... do you have problems running any other command lines from
your php scripts?  That could be one thing is that it's looking in the wrong
places for your scp/ssh/scp calls.  Other than that, any errors in the
error_log?





>


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org