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 usersdefines which usernames can access this module.secrets filestores the username-password mapping in the format:
/etc/rsyncd.secrets:
backupuser:supersecret123
๐ธ The
backupuserdoes not need to exist on the OS. ๐ธ This authentication is entirely internal to the rsync daemon. ๐ธ/etc/passwdand 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 usersis 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.confand 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โ
| Action | Command |
|---|---|
| Stop & disable daemon | sudo systemctl stop/disable rsync |
| Remove config file | sudo rm /etc/rsyncd.conf |
| Remove secrets file (optional) | sudo rm /etc/rsyncd.secrets |
| Remove systemd override | sudo systemctl revert rsync |
| Check service status | sudo 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โ
| Option | Description |
|---|---|
--delete | Delete files on the target that no longer exist in the source. |
--delete-before | Perform deletions before transfer. |
--delete-during | Delete files during the transfer (more efficient). |
--delete-excluded | Also delete files that were excluded with --exclude. |