Automate Rsync without Password using Rsync Daemon

In order to automate rsync without any password or transports, we need to setup the rsync daemon on one of the server. Suppose we want to sync data from a slave server to a live server.

Configuring the Slave Server

In the slave server we have to run the rsync daemon which accepts connections from live. Inorder to do this, we have to first edit the

/etc/rsyncd.conf

Add an entry in

/etc/rsyncd.conf
with the following template
[Module_Name]
        path = Filesystem_Path
        comment = Comment
        auth users = Authenticated_Users
        secrets file = User_Password_file
        hosts allow = IP_Addresses

The parameters as shown in italics have to be edited.

  • Module_Name : A name to the module
  • Filesystem_Path : The folder that is to be synced
  • Comment : A comment about the entry
  • Authenticated_Users : List of users separated by space who can access the module / path
  • User_Password_file : The location of the file containing the username and passwords
  • IP_Addresses : List of IP Addresses that can connect to the rsync daemon to sync.

The User_Password_file is a file which is only readable by the rsync daemon. The contents of the file have the template

User:Password

An example implementation of the rsyncd.conf and password file is as shown below.

[images]
        path = /var/www/images/
        comment = Images copy
        auth users = user123
        secrets file = /etc/rsyncd.secret
        hosts allow = 192.168.1.2 192.168.1.34

Contents of rsyncd.secret

user123:password123

It is to be noted that the permission of the secret file should be 400, i.e, readable only by the owner that is the process which runs rsync

chmod 400 rsyncd.secret

Finally start the rsync daemon using the command rsync --daemon

Configuration on Live Server

In the slave server you just have to run the command

rsync -r rsync_user@rsync_host::rsync_module Target_Folder --password-file Password_File

The parameters as shown in italics have to be edited.

  • rsync_user : Name of the user that has access to the Module with Module_Name
  • rsync_host : The server running rsync daemon
  • rsync_module : Name of the rsync module
  • Target_Folder : The target folder that has to be synced with the module.
  • Password_File : The location of the file containing the password

A sample command would be rsync -r user123@192.168.1.1::images /live/images --password-file rsync.pwd

Contents of rsync.pwd password123

The password file would also have the same properties as the secret file discussed in server configuration.

Thus running this would sync Alternatively adding this command on a cron job could help you sync periodically.

192.168.1.1:/var/www/images to 192.168.1.X:/var/www/images

Happy Syncing...
:)

09 Feb, 2010
Comments (2)
  • It does not work from

    It does not work from Windows. Can you help?
    I am trying to sync on Windows box from Linux box.

    By Anonymous on 25 Oct, 2011
  • thanks

    After lots of googling, your tutorial on *both* sides of the communication -- including the details of the configuration file -- helped me understand what I was doing wrong. Thanks for posting this!

    By Anonymous on 26 Nov, 2010
You may also like
Tags
On Facebook
Email Newsletter