Question

I want to use PHP to run a shell script that sends a file from server 1 to server 2. I have the server 1 public key written to the server 2 authorized_keys and it works perfectly.

For some reason the following script doesn't actually send the file from server 1 to server 2:

// This is a webpage at http://server1.com/sendfile.php
<?php
if($_POST['a'])
{
        echo '<pre>';
        echo passthru('./scp.sh');
        echo '</pre>';
}
?>

<form method="post">
<button name="a" value="Af">Send File</button>
</form>

//This is the contents of scp.sh
scp ../dbexport/db.txt someuser@server2.net:

So when I execute from scp.sh from terminal, everything works fine - the file actually gets sent and received.

But when I go to http://server1.com/sendfile.php and press the button, the php file actually executes the shell file (i confirmed this by putting echo statements before and after scp command), but the file is never successfully received by server2.com

Does anyone know why this might be?

Was it helpful?

Solution

Marc B answered my question with a comment...posting here

did you add the key to the webserver's account's authorized_keys? Just because it works from a shell running under YOUR permissions means absolutely nothing to a shell running under the webserver's ID. – Marc B Jan 9 at 19:47

ooooh yeahhhhh....i forgot about that – John Jan 9 at 19:57

yup it worked. thanks Marc! – John Jan 9 at 20:42

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top