rsync remote servers without password

Setup Rsync Between Two Servers Without Password

Rsync allows you to transfer files & data between two servers on same or different machines. Generally, it asks for password on remote host before starting file transfer. Here is how to setup Rsync between two servers without password requirement.


Setup Rsync Between Two Servers Without Password

Here are the steps to configure rsync between two servers without password. Let us say you want to sync local folder /home/ubuntu/data to /home/backup/ at 54.43.32.21.


1. Test password requirement

First run rsync command to make sure that you are actually asked for password. Replace user, file locations and IP address below as per your requirement.

$ sudo rsync -avz -e ssh /home/ubuntu/ user@54.43.32.21:/home/backup/

If you get a prompt for password, then follow the next steps.

Also read : How to Change Apache Log location


2. Generate Keys using SSH-keygen

Use ssh-keygen tool on local machine to generate public and private keys.

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

When you are asked for passphrase, just press enter/return key and don’t enter any password.

Also read : Redirect to Another Domain Without Changing URL


3. Copy public key to remote host

Use ssh-copy-id command to copy public key to remote host

$ sudo ssh-copy-id -i ~/.ssh/id_rsa.pub 54.43.32.21

You will be asked the password of remote host. On entering it successfully, it will copy public key to remote host.

If ssh-copy-id command does not work, use the following method.

Open public key on your local machine.

$ sudo vi ~/.ssh/id_rsa.pub

Copy the contents of the file. Close the file without saving (:q!)

On your remote machine, open the folder that contains authorized keys.

$ sudo vi /root/.ssh/authorized_keys

Paste the key content that you copied above. Save and close the file (:wq!)

Also read : How to Prevent SQL Injection in PHP


4. Perform Rsync with Remote Server

Now you should be able to rsync with remote host without using password.

$ sudo rsync -avz -e ssh /home/ubuntu/ user@54.43.32.21:/home/backup/

In this article, we have learnt how to setup rsync between two remote servers without using password. The key part is step 2. When you create public and private keys do not enter any password, when you are asked to enter passphrase. Otherwise, when you try to rsync you will be asked for the same password.

Also read : What File Permissions for Apache File/Folders


Leave a Reply

Your email address will not be published. Required fields are marked *