The connection was refused because you were using a non-standard rsync port, see the comments by user roaima.
For simplicity, I expect user public_rsync
with home directory /home/public_rsync
exists on the destination host (192.xxx.xxx.xxx, where the daemon is running) and the service is not blocked by your firewall.
Start with this sample /etc/rsyncd.conf
(passwords are enabled later):
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsync.log
[checkpoints]
path = /home/public_rsync/checkpoints
comment = RSYNC FILES
read only = false
uid = public_rsync
gid = public_rsync
#auth users = secondaryvm
#secrets file = /etc/rsyncd.secrets
timeout = 300
Explanation:
- remove
port = 12000
to use default port 873
- change module name from
[files]
to [checkpoints]
- change the path to the module directory to
/home/public_rsync/checkpoints
- change
read only = true
to false
to be able to push files to the server
- add
uid
/ gid
to use this username / group when transferring files
Then restart the server:
sudo systemctl restart rsync
1. Test rsync
on the destination host as user public_rsync
List all listable modules with rsync localhost::
, it should return the module name and the description:
[email protected]:~$ rsync localhost::
checkpoints RSYNC FILES
Create directory checkpoints
and a test file in this directory:
[email protected]:~$ mkdir ~/checkpoints
[email protected]:~$ echo helloworld > ~/checkpoints/helloworld.txt
List all files of our module:
[email protected]:~$ rsync localhost::checkpoints
drwxrwxr-x 4,096 2020/10/30 18:26:01 .
-rw-rw-r-- 11 2020/10/30 18:26:01 helloworld.txt
2. Test rsync
from the source host, make sure pull/push are working
Test pull:
$ rsync 192.xxx.xxx.xxx::checkpoints/helloworld.txt /tmp/
$ cat /tmp/helloworld.txt
helloworld
Test push:
$ rsync /tmp/helloworld.txt 192.xxx.xxx.xxx::checkpoints/helloworld_push.txt
List files of module checkpoints
again:
$ rsync 192.xxx.xxx.xxx::checkpoints
drwxrwxr-x 4,096 2020/10/30 18:29:06 .
-rw-rw-r-- 11 2020/10/30 18:26:01 helloworld.txt
-rw-r--r-- 11 2020/10/30 18:29:06 helloworld_push.txt
3. Enable authentication
Now that we know rsync
works as expected, enable authentication on the destination host:
Create text file /etc/rsyncd.secrets
with username and password for user secondaryvm
(the username is arbitrary, no user account needed):
[email protected]:~$ sudo tee /etc/rsyncd.secrets > /dev/null <<'EOF'
secondaryvm:12345
EOF
[email protected]:~$ sudo chmod 600 /etc/rsyncd.secrets
Uncomment auth users
and secrets file
in /etc/rsyncd.conf
, restart the server:
[email protected]:~$ sudo systemctl restart rsync
4. Test authentication (from source host)
Connecting without credentials should not be possibly any more, you're supposed to enter a password:
$ rsync 192.xxx.xxx.xxx::checkpoints
Password:
@ERROR: auth failed on module checkpoints
rsync error: error starting client-server protocol (code 5) at main.c(1675) [Receiver=3.1.3]
Provide username and password for the connection, e.g.
$ echo '12345' > rsync_pass
$ chmod 600 rsync_pass
$ rsync --password-file=rsync_pass [email protected]::checkpoints
If anything doesn't work, add verbosity with option -v
and check the daemon log /var/log/rsync.log
.
/etc/rsyncd.conf
. Areauth users
andsecrets file
defined and properly setup?sudo systemctl status rsync
on backup side