I had this problem too - I hope this helps. For me, the problem was the syntax required for alternate port ssh. Here are two working examples:
Execute this from the target backup machine, which pulls from source to target backup:
rsync -av --delete -e 'ssh -p 59333 -i /home/user/.ssh/id_rsa' user@10.9.9.3:/home/user/Server/ /home/user/Server/
Execute this from the source machine, which sends from source to target backup:
rsync -av --delete -e 'ssh -p 59333 -i /home/user/.ssh/id_rsa' /home/user/Server/ user@10.9.9.3:/home/user/Server/
This solution assumes you already exchanged your public key with target and/or vice versa using ssh-copy-id -p 59333
. This wonky syntax is not required if you use port 22, in which case you can use the i
flag and it will procure the public key from the default location in ~/.ssh/id_rsa.pub
. Here is an example without alternate port that also works fine:
Execute this from the target backup machine, which pulls from source to target backup:
sudo rsync -avi --delete user@10.9.9.3:/var/www/ /media/sdb1/backups/www/
Execute this from the source machine, which sends from source to target backup:
sudo rsync -avi --delete /media/sdb1/backups/www/ user@10.9.9.3:/var/www/
If you are still getting prompted for a password, then you need to check your ssh configuration in /etc/ssh/sshd_config
and verify that the users in source and target each have the others' respective public ssh key. I left this amount of detail because the syntax left by two others above still does not work for me.
1When you ssh to the remote server are you doing it as root ? – Pierre-Alain TORET – 2015-10-31T22:07:33.790
Yes I ssh as root. I had tried the same steps as user but am prompted for password when I ssh – China Diapers – 2015-10-31T22:10:10.750
the following isn't the cause of the problem but just a point.. I think with the -i you should remove
.pub
because -i specifies the private key, and you can remove-i ~/.ssh/id_rsa
completely because that's the default afaik. (unless you set a different default), but even then you don't want .pub after the -i but that's not the erason for your problem since you say ssh is working fine, it's rsync that isn't. – barlop – 2015-10-31T22:10:36.613@ChinaDiapers For those who do not want to use the daemon mode, and have an alternate port in use and/or store their
id_rsa.pub
in a separate location, I left some examples below. Moreover, even without alternate port and in the standard location, I cannot get the officially accepted answer to work. – oemb1905 – 2019-07-07T07:21:33.727