Index ¦ Archives ¦ Atom ¦ RSS

Syncing Files from macOS to Fedora Linux with rsync and SSH

When transferring files between a macOS workstation (such as my MacBook Air ankaa) and a Fedora Linux machine (my Lenovo ThinkPad T450 taylor), rsync over SSH provides fast, incremental synchronization. Once the taylor host alias is configured in ~/.ssh/config, rsync automatically inherits your target IP address (192.168.0.10), username, and custom identity key without requiring explicit connection flags on every run.



Short Flags vs. Long Options

Short options (like -a, -v, -z) are single-letter abbreviations designed for quick terminal input. Long options (like --archive, --verbose, --compress) perform the exact same operations while remaining self-documenting and easier to read in scripts and documentation.

Short Flag Equivalent Long Option What It Does
-a --archive Enables recursion and preserves permissions, modification times, ownership, and symlinks.
-v --verbose Displays detailed information about which files are being transferred.
-z --compress Compresses file data during network transit to speed up transfer times over Wi-Fi.
-P --progress --partial Combined shortcut: --progress shows the live bar; --partial keeps incomplete files if the connection breaks for resuming.
-n --dry-run Performs a trial run showing what would change without transferring or modifying any files.
-u --update Skips files that are already newer on the destination host (taylor).

What --update Adds to Your Workflow

Adding --update instructs rsync to compare file timestamps across both machines:

  • If a file on taylor is newer than the corresponding file on your Mac, rsync will not overwrite it.
  • This prevents accidentally rolling back recent edits made directly on the remote Linux workstation.

Long-Option Use Cases and Dry Runs

  1. Transferring a Single File:

    rsync --archive --verbose --update --progress --partial ~/Downloads/document.pdf taylor:~/Downloads/
    
  2. Transferring Directory Contents vs. Subdirectories:

    • Copy contents directly (trailing slash on Photos/):

      rsync --archive --verbose --update --compress --progress --partial ~/Photos/ taylor:~/Pictures/
      
    • Copy the directory itself (no trailing slash on Photos):

      rsync --archive --verbose --update --compress --progress --partial ~/Photos taylor:~/Pictures/
      
  3. Running a Dry Run with Long Options:

    rsync --dry-run --archive --verbose --update --progress --partial ~/Documents/ taylor:~/Documents/
    

Filtering macOS Metadata Files

macOS automatically generates hidden metadata files such as .DS_Store and .localized that clutter Linux directories. You can exclude them per command or configure a permanent global exclusion list.

Option 1: Inline Exclusions (Per-Command)

Pass individual --exclude parameters directly to rsync:

rsync --archive --verbose --update --progress --partial \
  --exclude='.DS_Store' \
  --exclude='.localized' \
  --exclude='._*' \
  --exclude='.CFUserTextEncoding' \
  ~/Desktop/ taylor:~/Desktop/

Common macOS metadata files to exclude include:

  • .DS_Store (Finder folder display settings)
  • .localized (system folder localization hints)
  • ._* (AppleDouble resource fork files created on non-HFS/APFS volumes)
  • .CFUserTextEncoding (user text encoding preferences)
  • .Trashes and .Spotlight-V100 (system trash and Spotlight index directories)

One-Liner with Zsh Brace Expansion

Because macOS uses zsh as its default shell, you can collapse multiple --exclude flags into a single brace expansion one-liner:

rsync --archive --verbose --update --progress --partial --exclude={'.DS_Store','.localized','._*','.CFUserTextEncoding'} ~/Desktop/ taylor:~/Desktop/

The shell expands {...} into separate --exclude arguments before executing rsync.

Cleaning Up Existing Metadata Files on Linux

If macOS metadata files were already synced to taylor previously, you can remove them remotely via SSH:

ssh taylor "find ~/Desktop -name '.DS_Store' -o -name '.localized' -delete"

SSH Host Key Troubleshooting and Connection Verification

When reinstalling Fedora Linux on taylor while retaining the same local IP address (192.168.0.10), SSH generates a new host key fingerprint. Attempting to copy keys or connect from ankaa will trigger a remote host identification warning because the stored fingerprint in ~/.ssh/known_hosts no longer matches.

Step 1: Remove the Stale Host Key Entry

Clear the old fingerprint for 192.168.0.10 from ankaa:

ssh-keygen -R 192.168.0.10

This removes the outdated entry from ~/.ssh/known_hosts and saves a backup copy of the previous file.

Step 2: Copy Your Public Key and Accept the New Fingerprint

Re-run ssh-copy-id using your custom-named public key:

ssh-copy-id -i ~/.ssh/porfirio@ankaa.pub porfirio@192.168.0.10

Type yes when prompted to trust the new host fingerprint, then enter your Fedora password to install the public key on taylor.

Step 3: Configure ~/.ssh/config and Test Connections

Ensure your SSH client configuration on ankaa points to the private key file (without the .pub extension):

nano ~/.ssh/config
Host taylor
    HostName 192.168.0.10
    User porfirio
    IdentityFile ~/.ssh/porfirio@ankaa

Enforce strict permissions on the configuration file:

chmod 600 ~/.ssh/config

You can now verify passwordless authentication using three methods:

  1. Direct connection with explicit identity flag:

    ssh -i ~/.ssh/porfirio@ankaa porfirio@192.168.0.10
    
  2. Non-interactive remote command execution:

    ssh -i ~/.ssh/porfirio@ankaa porfirio@192.168.0.10 "hostname; uptime"
    
  3. Alias-based connection:

    ssh taylor
    

If SSH still prompts for a password, run the connection in verbose mode (-v) to inspect key negotiation:

ssh -v -i ~/.ssh/porfirio@ankaa porfirio@192.168.0.10

© Porfirio Páiz. Built using Pelican. Theme by Giulio Fidente on github.