Skip to main content

rsync Daemon

๐Ÿ“ˆ Architecture Overviewโ€‹


๐Ÿ›  Server Configurationโ€‹

/etc/rsyncd.conf:

[usbbackup]  # Module name
path = /tmp/rsync-test # Destination directory on the server
read only = false
auth users = backupuser # User defined for rsync access
secrets file = /etc/rsyncd.secrets

๐Ÿ” Authentication Explainedโ€‹

  • auth users defines which usernames can access this module.
  • secrets file stores the username-password mapping in the format:

/etc/rsyncd.secrets:

backupuser:supersecret123

๐Ÿ”ธ The backupuser does not need to exist on the OS. ๐Ÿ”ธ This authentication is entirely internal to the rsync daemon. ๐Ÿ”ธ /etc/passwd and OS accounts are not involved. โœ… This creates a safer, isolated login system for file sync.

Make sure to restrict the file permission:

sudo chmod 600 /etc/rsyncd.secrets

๐Ÿ’ก If auth users is omitted, the module becomes publicly writable (not recommended).

To start the daemon:

sudo systemctl daemon-reload
sudo systemctl restart rsync

๐Ÿ’ป Client Usageโ€‹

1. Test the Connectionโ€‹

# List available modules
rsync --list-only rsync://backupuser@192.168.68.51/

You will be prompted to enter the password.

2. Sync Filesโ€‹

# Upload: Sync local โ†’ server
rsync -av /some/local/folder/ rsync://backupuser@192.168.68.51/usbbackup/

# Download: Sync server โ†’ local
rsync -av rsync://backupuser@192.168.68.51/usbbackup/ /some/local/folder/

โš ๏ธ Common Error & Solutionsโ€‹

โ— Problemโ€‹

rsync: [receiver] mkstemp "/.hello-rsync.txt.CH2LTc" (in usbbackup) failed: Permission denied (13)

Even though the rsync daemon runs as root, it doesn't write as root by default during file transfers.

By default, if uid and gid are not specified in rsyncd.conf, the daemon uses nobody:nogroup, which lacks permissions to write to /tmp/rsync-test.

โœ… Solution 1: Change Directory Ownership to nobodyโ€‹

sudo chown -R nobody:nogroup /tmp/rsync-test
sudo chmod -R 755 /tmp/rsync-test

This allows the daemon (running as nobody) to write data successfully.

โœ… Solution 2: Use a Specific User (e.g., eric)โ€‹

Update rsyncd.conf:

check the uid and gid settings:

id
# uid=1000(eric) gid=1000(eric) groups=1000(eric) ...

Then modify /etc/rsyncd.conf:

[usbbackup]
path = /tmp/rsync-test
read only = false
uid = 1000
gid = 1000
auth users = backupuser
secrets file = /etc/rsyncd.secrets

Then adjust directory permissions:

sudo chown -R eric:eric /tmp/rsync-test

๐Ÿง  Optional Enhancementsโ€‹

1. Enable Module Listingโ€‹

This helps tools like Hyper Backup or CLI debugging:

list = yes
comment = USB Backup POC
rsync rsync://backupuser@192.168.68.51/
# Output:
# usbbackup USB Backup POC

2. Restrict IP Access (Firewall)โ€‹

Allow access only from LAN or specific clients:

hosts allow = 192.168.68.0/24
hosts deny = *

Or even stricter:

hosts allow = 192.168.68.50

3. Enable Persistent Logging (via systemd)โ€‹

sudo systemctl edit rsync

Add the following to the override:

[Service]
ExecStart=
ExecStart=/usr/bin/rsync --daemon --no-detach --config=/etc/rsyncd.conf
StandardOutput=journal
StandardError=journal

Then reload:

sudo systemctl daemon-reload
sudo systemctl restart rsync

Watch logs in real-time:

journalctl -u rsync -f

๐Ÿ”„ Reverting to Defaultโ€‹

1. Stop & Disable the Daemonโ€‹

sudo systemctl stop rsync
sudo systemctl disable rsync

2. Remove Config Filesโ€‹

sudo rm /etc/rsyncd.conf
sudo rm /etc/rsyncd.secrets

Optionally, you may only remove rsyncd.conf and keep the secrets file.

3. Remove systemd Overrides (If Applied)โ€‹

sudo systemctl revert rsync

4. Confirm Statusโ€‹

sudo systemctl status rsync

Expected output:

โ— rsync.service - fast remote file copy program daemon
Loaded: loaded (/lib/systemd/system/rsync.service; disabled; vendor preset: enabled)
Active: inactive (dead)

Summaryโ€‹

ActionCommand
Stop & disable daemonsudo systemctl stop/disable rsync
Remove config filesudo rm /etc/rsyncd.conf
Remove secrets file (optional)sudo rm /etc/rsyncd.secrets
Remove systemd overridesudo systemctl revert rsync
Check service statussudo systemctl status rsync

๐Ÿงน Synchronization Notes: --deleteโ€‹

By default, rsync does not delete files on the destination that are missing from the source.

sudo rsync -av ./ rsync://backupuser@192.168.68.51/usbbackup/
  • โœ… New and updated files are synced.
  • โŒ Deleted source files remain on the server.

To keep the destination fully in sync (mirroring):

sudo rsync -av --delete ./ rsync://backupuser@192.168.68.51/usbbackup/

๐Ÿšจ Caution: This will remove files on the server that are not present on the client.

๐Ÿงช Always test first:

sudo rsync -av --delete --dry-run ./ rsync://backupuser@192.168.68.51/usbbackup/

Common --delete Optionsโ€‹

OptionDescription
--deleteDelete files on the target that no longer exist in the source.
--delete-beforePerform deletions before transfer.
--delete-duringDelete files during the transfer (more efficient).
--delete-excludedAlso delete files that were excluded with --exclude.