I have followed the following guide to setup Rsync with SSH between my local machine and a remote server:
I performed the below as root:
rsync -avz -e ssh /home/user/dir root@192.168.200.10::Backup/dir-> prompts for passwordssh-keygen-> Key generatedssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.200.10-> confirmation that keys were copiedssh 192.168.200.10-> Accesses the remote server without promting for passwordrsync -avz -e ssh /home/user/dir root@192.168.200.10::Backup/dir-> Prompts for password
Is it not strange that I can SSH into the remote server without being prompted for the password but do when using rsync?
I can see .ssh/authorized_keys on the remote server.
Where am I doing wrong?
43 Answers
You are mixing two separate connection modes: with a remote shell (-e ssh) and without a remote shell, thru a rsync daemon (identified by the double colon).
The manual states:
CONNECTING TO AN RSYNC SERVER
It is also possible to use rsync without a remote shell as the trans- port. In this case you will connect to a remote rsync server running on TCP port 873.
...... you either use a double colon :: instead of a single colon to separate the hostname from the path, or you use an rsync:// URL.
....... Some paths on the remote server may require authentication. If so then you will receive a password prompt when you connect. You can avoid the password prompt by setting the environment variable RSYNC_PASSWORD to the password you want to use or using the --password-file option. This may be useful when scripting rsync.
Probably the simplest way to obtain passwordless authentication for you is to modify the command above as follows:
rsync -avz -e ssh /home/user/dir root@192.168.200.10:/absolute/path/to/Backup/dir 1 Your username on your local account is probably not root, which is the username you use with Rsync.
ssh remotehost…is effectively the same as:
ssh localUserName@remotehostSorry, I didn't notice that you already said you’re running as root.
I also didn’t notice that you are using the module syntax with two colons (::) after the remote hostname. I don’t think the guide you followed covers connecting to Rsync this way, and that you should be fine if you use the single colon syntax, for example:
rsync -avz -e ssh /home/user/dir root@192.168.200.10:/some/path/backups/dir 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.