rsync

Rsync This section explains how to use rsync securely over SSH to synchronize files between remote systems. It provides example commands, flag breakdowns, and highlights best practices for data transfer and encryption.


By using ssh+rsync in combination, you got pretty powerful file transfer tool, unlike scp rsync over ssh is much more flexible, like swiss army knife.

rsync -avzP --partial -e "ssh" /tmp/large.tar.gz user1@httpd.hiddenssh.net:/tmp/large.tar.gz 

-e "ssh" β†’ Uses **SSH** as the transport method for secure file transfers

-a β†’ Preserves file permissions, timestamps, symbolic links, and directories
-v β†’ Enables **verbose mode** to see details during the transfer
-z β†’ Compresses data for **faster transfers** over slow connections
--partial / -P β†’ Keeps **partially transferred files** if interrupted (useful for large files)
--progress β†’ Displays real-time **progress** per file


πŸ“Œ Copying Files Locally with Rsync

Rsync is not limited to remote transfersβ€”it can be used for **local file copies** with better speed and efficiency than `cp`:

rsync -av /tmp/file.tar.gz /dev/shm/ 

πŸš€ Rsync vs. Traditional Commands Rsync is not just a file copier it outperforms cp mv and even rm -rf with; better speed, incremental updates, and error recovery.

πŸ”Ή More Useful Rsync Options:
rsync --remove-source-files β†’ Moves files (like `mv` but safer, keeping empty directories)
rsync --delete β†’ Deletes files from the destination that no longer exist in the source
rsync --dry-run β†’ Simulates the command **without making changes**
rsync -e "ssh -p 2222" β†’ Uses a custom **SSH port (e.g., 2222)**
rsync --bwlimit=1000 β†’ Limits bandwidth usage (in KB/s) to **prevent network congestion**


πŸ”Ή Advanced Rsync SSH Options:

rsync -e "ssh -i ~/.ssh/id_rsa" β†’ Uses a **specific SSH key** for authentication
rsync -e "ssh -o StrictHostKeyChecking=no" β†’ **Disables SSH host key verification**
rsync -e "ssh -C" β†’ **Enables SSH compression**, useful for slow connections
rsync -e "ssh -o ControlMaster=auto -o ControlPath=/tmp/ssh_mux_%h_%p_%r -o ControlPersist=600" β†’
   Uses **SSH multiplexing** for multiple rsync sessions, reducing authentication overhead
rsync -e "ssh -T" β†’ Disables SSH pseudo-terminal allocation (useful in scripts)