Install and configure rsync – daemon
Introduction
In this article I will look at how to install and configure rsync, “an utility for efficiently transferring and synchronizing files between a computer and an external hard drive and across networked computers by comparing the modification times and sizes of files.” in Wikipedia
In other words, a backup utility.
I will focus on installing rsync on Debian based Linux distributions, such as Ubuntu. The configuration part should also be valid for other main Linux distributions, such as Fedora.
Requirements
A machine with a Debian based Linux distro installed and updated, that will function as the rsync server, and another Linux machine with rsync installed, which will be the rsync client to test connectivity.
If you do not have yet a machine installed with a Debian based Linux distro, I’ll leave you the links for two of the most popular ones:
https://www.debian.org/releases/buster/installmanual
https://ubuntu.com/server/docs/installation
Install and configure rsync
Installing rsync
To install rsync, on a terminal window type:
sudo apt-get install rsync
Configuring rsync
editing the necessary files – rsyncd.conf
After installing rsync, it is needed to create and edit a pair of files, the first one being the configuration file as it is not created automatically upon installation.
To create the file, replace nano with your text editor of choice, type:
sudo nano /etc/rsyncd.conf
The file is divided, largely, in two sections, the global section, the first four lines and the modules section, where each rsync module, or “share” is defined.
Below is an example of a rsyncd.conf file:
motd file = /etc/rsyncd.motd
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
[public]
path = /public
comment = public
uid = nobody
gid = nobody
read only = no
list = yes
auth users = rsync1
secrets file = /etc/rsyncd.secrets
If you’d like to read about the several options in detail, please read this article. I will focus on what is strictly necessary to change in order for my “share” or module to be accessible and functional.
The word public, in brackets, is the given name to the module, the area(s) that will be available to reach from the rsync client. You can give it any name you’d like.
path, is exactly that, the physical path to the resource you’d like to be available over rsync
comment is just a description of the module that will be shown when you list the available modules on the Rsync server.
auth users – here goes the users that will have access to this module. These users do not have to necessarily exist on the system. These are rsync users that should be listed in the secrets file that is described in the next line of the configuration file
secrets file – well, this is the file where the rsync users are created and available for the Rsync server to read.
The secrets file
As shown in the above snippet, the secrets file is created in the /etc directory with the name rsyncd.secrets and it contains the pairs of usernames and password to use with rsync. The format is as follow:
user:password
Example:
rsinc1:P@ssw0rd
Once you have the secret files created, we need to protect it from unwanted eyes – yes, it is in plain text.
To protect the secrets file type:
sudo chmod 0640 /etc/rsyncd.secrets
And with that done, what is left is to test if all is working.
Starting the rsync server daemon
On the server machine, type:
sudo rsync --daemon
No message should pop-up. Type:
sudo ps -x | grep rsync
You should get a line with the running rsync process. If so, all is good.
Let’s go to the client machine!
Connecting to the rsync server
To list all the available modules on the rsync server, from the client Linux machine, type:
rsync -rtn rsync://user@host
If you’d like to list into a module, type:
rsync -rtn rsync://user@host/module
It will ask you for the password and the module should be listed.
And with that we have the Rsync server daemon configured and installed.
Now, as stated in the beginning of the article, rsync is used to perform backups. Usually backup of files over the network, to an rsync backup server using scheduled jobs to do so. I will detail that in another article, as it is out of scope for this one.
References:
https://en.wikipedia.org/wiki/Rsync
https://download.samba.org/pub/rsync/rsync.html
https://rsync.samba.org/how-rsync-works.html
https://bovitron.com/blogostu/2019/04/14/rsync-error-starting-client-server-protocol-code-5/
https://www.atlantic.net/vps-hosting/how-to-setup-rsync-daemon-linux-server/
https://ss64.com/bash/rsync.html
As always, if you found this article useful, share it with your friends.
If you have any questions or suggestions, leave your comment.
Thank you for reading!
uid = nobody
gid = nobody
Should change to your currently logged in user name and group unless yours happen to be above.
Example for
my settings are
uid = edward
gid = edward