How to synchronize local and remote folders using rsync from inside php script without asking for password?
I have already set up a public key to automate login on a remote server for my user.
So this works without any problems from cli:
rsync -r -a -v -e "ssh -l user" --delete ~/local/file 111.111.11.111:~/remote/;
But when I try to run the same with a PHP script (on a web page on my local server):
$c='rsync -r -a -v -e "ssh -l user" --delete ~/local/file 111.111.11.111:~/remote/';
//exec($c,$data);
passthru($c,$data);
print_r($data);
This is what I get:
255
And not a single file is downloaded from the local to the remote server.
Searching the net, I found this key :
" BASh Expect shell code, , root. nobody apache ( Apache). , phpSuExec, Suhosin suPHP, , ."
, , " " PHP, "apache". , script , - , ... !
UPDATE:
- :
passthru('ssh user@111.111.11.111 | ls',$data);
foder, , . rsync, PHP script.
UPDATE:
, " ssh $HOME/.ssh/, PHP Apache, $HOME; $HOME/.ssh/id_dsa. , , , ."
rsync, :
if($con=ssh2_connect('111.111.11.111',22)) echo 'ok!';
if(ssh2_auth_password($con,'apache','xxxxxx')) echo ' ok!';
if(ssh2_scp_send($con,'localfile','/remotefolder',0755)) echo ' ok!';
: 0644
: 0775
, php BASh ...
@Yzmir Ramirez : " , " -, apache "- . script , .ssh .
, . - , , , .