How to Setup Rsync with SSH on UNIX / Linux (rsync without password)

Question: When I perform rsync, it asks for my password on the remote server before starting the transfer. I would like to avoid this, and perform rsync without a password. Can you explain with an example on how to setup rsync over SSH without a password on Linux?

Answer: The following steps explain how to setup rsync over ssh that doesn’t ask for a password. This is helpful when you are scheduling a cron job for automatic backup using rsync.

1. Test rsync over ssh (with password):

Do a rsync to make sure it asks for the password for your account on the remote server and successfully copies the files to the remote server.

The following example will synchronize the local folder /home/root/ to the remote folder /backup/ (on server).

This should ask you for the password of your account on the remote server.

rsync -avz -e ssh /home/root/ ramesh@

2. ssh-keygen generates keys.

Now setup SSH so that it doesn’t ask for a password when you perform SSH. Use ssh-keygen on the local server to generate public and private keys.

$ ssh-keygen
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

Note: When it asks you to enter the passphrase just press enter key, and do not give any password here.

3. ssh-copy-id copies public key to remote host

Use ssh-copy-id, to copy the public key to the remote host.

ssh-copy-id -i ~/.ssh/

Note: The above will ask the password for your account on the remote host, and copy the public key automatically to the appropriate location.

4. Perform rsync over ssh without password

Now, you should be able to ssh to remote host without entering the password.


Perform the rsync again, it should not ask you to enter any password this time.

rsync -avz -e ssh /home/root/ root@

If you want to schedule this rsync backup job automatically, use cron to set it up.

You may also like...