I have already set up a public key to automate the login on remote server for my user.
So this is running without any problem from cli:
rsync -r -a -v -e "ssh -l user" --delete ~/local/file 220.127.116.11:~/remote/;
But, when I try to run the same from a PHP script (on a webpage in my local server):
$c='rsync -r -a -v -e --log-file=FILE "ssh -l user" --delete ~/local/file 18.104.22.168:~/remote/'; //exec($c,$data); passthru($c,$data); print_r($data);
This is what I receive:
2011/01/23 19:18:29  rsync: connection unexpectedly closed (0 bytes received so far) [sender] 2011/01/23 19:18:29  rsync error: unexplained error (code 255) at io.c(601) [sender=3.0.7]
The permissions qre set like this:
Local: chmod 600 ~/.ssh/local-rsync-key chmod 600 ~/.ssh/local-apache-key chmod 700 ~/.ssh/ Remote: chmod 600 ~/.ssh/authorized_keys chmod 700 ~/.ssh/ chmod 700 ~/
I registered two keys on ~/.ssh/authorized_keys:
I went dry of ideas... I guess I have to do something else in the remote /etc/ssh/sshd_config file. I am running Nginx in both servers. Thanks for any help.
While I cannot get rsync, this is how I got to transfer the file from local to remote:
if($con=ssh2_connect('22.214.171.124',22)) echo 'ok!'; if(ssh2_auth_password($con,'apache','xxxxxx')) echo ' ok!'; if(ssh2_scp_send($con,'localfile','/remotefolder',0755)) echo ' ok!';
Local file needs: 0644 Remote folder needs: 0775
I also read this suggestion: "I don't think you want to "copy the key somewhere where apache can get to it" - that's a security violation. Better to change the script to run as a secure user and then setup the .ssh keys for passwordless login between servers.
If somebody know how to do this, please, it would be of great help.