Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Secure RSync Transfers Between Raspberry Pi Displays

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide shows you how to securely transfer files between Raspberry Pi displays (or any Pi running a display) using rsync over SSH. You'll learn to set up SSH keys, use rsync with encryption, and automate backups without exposing your data. This is useful for updating display content, syncing media, or backing up configuration files across multiple Pis.

What You'll Need

  • Two Raspberry Pi devices (source and destination), each with a display or headless setup.
  • Both Pi's connected to the same network (or reachable over the internet).
  • SSH enabled on both Pi's (usually via raspi-config or systemctl).
  • rsync installed on both (usually pre-installed; if not, sudo apt install rsync).
  • Basic familiarity with the terminal.

Step-by-Step

  1. Enable SSH on both Pi's. If not already done, run sudo raspi-config on each Pi, go to Interface Options → SSH, and enable it. Alternatively, create an empty file named ssh in the boot partition of the SD card.
  2. Find the IP addresses. On each Pi, run hostname -I to get the local IP. Note the IP of the destination Pi (the one receiving files).
  3. Install rsync if needed. On both Pi's, run sudo apt update && sudo apt install rsync -y to ensure it's present.
  4. Generate an SSH key pair on the source Pi. On the source Pi (the one sending files), run ssh-keygen -t ed25519 -C "rsync-backup". Accept the default file location (~/.ssh/id_ed25519) and set a passphrase (recommended for security).
  5. Copy the public key to the destination Pi. Use ssh-copy-id user@destination-ip (replace user with your username on the destination, e.g., pi). Enter your password when prompted. This installs the key so future SSH connections don't require a password.
  6. Test SSH key authentication. Run ssh user@destination-ip from the source Pi. You should log in without a password (or with your key passphrase if set). Exit with exit.
  7. Run a basic rsync command. To transfer a directory (e.g., /home/pi/display) to the destination, run:
    rsync -avz --progress /home/pi/display/ user@destination-ip:/home/pi/display/
    The -a preserves permissions and timestamps, -v is verbose, -z compresses data, and the trailing slashes ensure the contents are copied correctly.
  8. Add encryption (if not already using SSH). rsync over SSH is encrypted by default when you specify user@host. To force encryption, you can add -e ssh explicitly: rsync -avz -e ssh /source/ user@destination:/dest/.
  9. Use a non-default SSH port (optional). If you changed the SSH port on the destination (e.g., to 2222), add -e "ssh -p 2222" to the rsync command.
  10. Set up a cron job for automation. To sync automatically, edit the crontab on the source Pi with crontab -e, then add a line like:
    0 2 * * * rsync -avz /home/pi/display/ user@destination-ip:/home/pi/display/ > /dev/null 2>&1
    This runs the sync daily at 2 AM. Adjust the schedule as needed.
  11. Test the automation. Run crontab -l to verify the entry, and manually run the rsync command to ensure it works without prompts.

Common Mistakes

  • Forgetting trailing slashes. A trailing slash on the source (/source/) copies the contents, not the directory itself. Without it, you get a nested directory.
  • Using the wrong IP or hostname. If the destination Pi's IP changes (DHCP), the sync fails. Use a static IP or hostname (e.g., pi-display.local) if possible.
  • Permission errors. If the destination directory is owned by another user, rsync may fail. Ensure the destination user has write permissions, or use sudo on the destination (but avoid running rsync as root on the source).
  • Ignoring SSH key passphrase. If you set a passphrase, cron jobs will fail because they can't prompt for it. Use ssh-agent or create a key without a passphrase for automated tasks (less secure but functional).
  • Not testing the command before scheduling. Always run the rsync manually first to catch syntax errors.

Tips

  • Use --delete carefully. Adding --delete removes files on the destination that no longer exist on the source. This is useful for mirroring but can cause data loss if the source is incomplete.
  • Compress large media files. The -z flag compresses data, but for already-compressed files (like JPEG, MP4), it adds overhead. Use -z only for text or uncompressed data.
  • Use --partial and --progress. These flags help resume interrupted transfers and show progress, useful for large files.
  • Set up a static IP or mDNS. On the destination Pi, configure a static IP in /etc/dhcpcd.conf or use avahi to access it as hostname.local.
  • Consider using a dedicated user. Create a limited user on the destination for rsync to reduce security risks.

Troubleshooting

  • Connection refused. Check that SSH is running on the destination: sudo systemctl status ssh. Also verify the IP and port.
  • Permission denied (publickey). Ensure the public key is correctly appended to ~/.ssh/authorized_keys on the destination. Re-run ssh-copy-id or manually copy the key.
  • rsync not found. Install rsync on both Pi's: sudo apt install rsync.
  • Slow transfer. If the network is slow, try disabling compression (-z) or using a wired connection. Also check for interference.
  • Files not appearing. Verify the source path and destination path are correct. Use ls on both sides to confirm.
  • Cron job not running. Check the cron log (sudo grep CRON /var/log/syslog) and ensure the rsync command works when run manually. Also make sure the script uses absolute paths (e.g., /usr/bin/rsync).

Frequently Asked Questions

Is rsync over SSH secure enough for sensitive data?

Yes, because SSH encrypts the entire session, including file contents and metadata. Using key-based authentication adds an extra layer of security.

Can I sync in both directions?

rsync is one-way by default. To sync both ways, you'd need to run two rsync commands (one in each direction) or use a tool like unison.

How do I exclude files from the transfer?

Use the --exclude flag, e.g., --exclude='*.tmp' or --exclude='cache/'. You can also use --exclude-from with a file containing patterns.

What is the difference between -a and -r?

-r recurses into directories, but -a (archive) includes recursion plus preserves permissions, timestamps, and other attributes. Always use -a for backups.

Can I use rsync over the internet?

Yes, but you must forward the SSH port on your router and use a dynamic DNS service if your IP changes. For security, consider using a VPN or SSH tunnel.

Why is my transfer slow over Wi-Fi?

Wi-Fi has higher latency and interference. Try using a wired Ethernet connection, or adjust the --bwlimit option to throttle and avoid congestion.