On this page 27 sections
- What rsync does
- The most useful option: -a
- Verbose output
- Understand the trailing slash
- Show transfer progress
- Dry run before copying
- Synchronize through SSH
- Use a custom SSH port
- Use an SSH private key
- Exclude files and directories
- Include only specific files
- Delete files that no longer exist in source
- Resume interrupted transfers
- Human-readable sizes
- Compression during transfer
- Limit bandwidth
- Compare files using checksums
- rsync daemon mode
- List files inside a remote module
- Download from an rsync module
- Recursive module inspection
- Interesting CTF files
- Check TCP port 873
- rsync over SSH versus rsync daemon
- Useful local backup command
- Useful remote transfer command
- Useful CTF enumeration workflow
What rsync does
rsync synchronizes files and directories locally or between systems. It only transfers differences when possible, making it efficient for backups, deployments and remote file transfers.
rsync SOURCE DESTINATIONThe most useful option: -a
Archive mode (-a) recursively copies directories while preserving common metadata such as permissions, timestamps and symbolic links. It is the most common starting point for rsync operations.
rsync -a source/ destination/Verbose output
-v shows which files are being processed. It is commonly combined with archive mode.
rsync -av source/ destination/Understand the trailing slash
The trailing slash on the source changes what rsync copies. source/ means copy the contents of the directory, while source means copy the directory itself.
rsync -av source/ destination/rsync -av source destination/Show transfer progress
--progress displays transfer progress for individual files. --info=progress2 provides an overall progress view for the transfer.
rsync -av --progress source/ destination/rsync -av --info=progress2 source/ destination/Dry run before copying
--dry-run shows what rsync would change without actually modifying files. It is especially useful before destructive synchronization operations.
rsync -av --dry-run source/ destination/Synchronize through SSH
rsync commonly uses SSH for encrypted remote transfers. The remote destination follows the user@host:path format.
rsync -av source/ user@192.168.1.10:/home/user/backup/rsync -av user@192.168.1.10:/var/www/ ./www/Use a custom SSH port
The -e option allows the SSH command used by rsync to be customised.
rsync -av -e "ssh -p 2222" source/ user@192.168.1.10:/backup/Use an SSH private key
A specific SSH private key can be selected through the SSH command passed with -e.
rsync -av -e "ssh -i id_rsa" source/ user@192.168.1.10:/backup/Exclude files and directories
--exclude prevents selected files or directories from being transferred.
rsync -av --exclude="*.log" source/ destination/rsync -av --exclude="cache/" source/ destination/rsync -av --exclude="*.log" --exclude="tmp/" source/ destination/Include only specific files
--include and --exclude can be combined to restrict synchronization to selected file patterns.
rsync -av --include="*/" --include="*.txt" --exclude="*" source/ destination/Delete files that no longer exist in source
--delete removes destination files that are absent from the source. This creates a closer mirror but can destroy data if the source or destination is wrong. Always consider a dry run first.
rsync -av --delete --dry-run source/ destination/rsync -av --delete source/ destination/Resume interrupted transfers
--partial keeps partially transferred files instead of deleting them when a transfer is interrupted.
rsync -av --partial --progress source/ destination/Human-readable sizes
-h displays file sizes in a more readable format.
rsync -avh --progress source/ destination/Compression during transfer
-z compresses file data while it is being transferred. It can help on slower links but may provide little benefit for files that are already compressed.
rsync -avz source/ user@192.168.1.10:/backup/Limit bandwidth
--bwlimit limits transfer bandwidth in KiB per second and can prevent rsync from consuming an entire connection.
rsync -av --bwlimit=1024 source/ destination/Compare files using checksums
Normally rsync determines whether files changed using size and modification time. -c forces checksum comparison, which is more thorough but consumes additional CPU and disk I/O.
rsync -avc source/ destination/rsync daemon mode
rsync can also run as a network daemon, commonly on TCP port 873. In daemon mode, directories are exposed as named modules instead of using SSH paths.
rsync rsync://192.168.1.10/rsync 192.168.1.10::List files inside a remote module
If a module permits listing, its contents can be viewed without downloading anything.
rsync rsync://192.168.1.10/backups/rsync 192.168.1.10::backupsDownload from an rsync module
In authorised CTF or lab environments, a readable module can be copied locally for offline inspection.
rsync -av rsync://192.168.1.10/backups/ ./backups/rsync -av 192.168.1.10::backups/ ./backups/Recursive module inspection
A recursive listing is useful before downloading a large module because it shows its directory structure and potentially interesting filenames.
rsync -r rsync://192.168.1.10/backups/Interesting CTF files
When a readable rsync module is exposed in a lab, configuration files, backups, SSH material, scripts and application files are usually more interesting than blindly downloading everything.
rsync -r rsync://192.168.1.10/files/Check TCP port 873
The traditional rsync daemon listens on TCP port 873. An open port does not automatically mean anonymous access is permitted, but it indicates that rsync daemon enumeration may be relevant.
nmap -sV -p 873 192.168.1.10rsync over SSH versus rsync daemon
user@host:/path normally indicates rsync transported through SSH, usually using TCP 22. host::module or rsync://host/module refers to rsync daemon mode, commonly using TCP 873.
rsync -av user@host:/remote/path/ ./local/rsync -av rsync://host/module/ ./local/Useful local backup command
For many everyday backup tasks, archive mode, human-readable output and progress provide a good combination.
rsync -avh --info=progress2 source/ backup/Useful remote transfer command
For SSH-based synchronization, archive mode together with progress gives a simple and reliable starting point.
rsync -avh --info=progress2 source/ user@host:/destination/Useful CTF enumeration workflow
In an authorised lab, first identify whether TCP 873 is exposed, list available modules, inspect a relevant module recursively and only then copy interesting data locally.
nmap -sV -p 873 TARGETrsync rsync://TARGET/rsync -r rsync://TARGET/MODULE/rsync -av rsync://TARGET/MODULE/ ./MODULE/