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' [email protected]:/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/ [email protected]:/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 [email protected]:/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/ [email protected]:/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.
.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.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.