Operations 13 min read

Master rsync: Essential Commands, Options, and Server Setup for Linux Operations

This guide explains how rsync synchronizes files and directories on Linux, details its most useful options, shows how to configure an rsync daemon with the required configuration files, and outlines the various command syntaxes for local and remote operations.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master rsync: Essential Commands, Options, and Server Setup for Linux Operations

rsync is a Linux command-line tool for synchronizing files and directories between two computers or between locations on the same machine, often used for backing up configuration files (dotfiles) to a repository such as GitHub.

Basic usage

$ rsync [options] src dest

Key behaviors include:

If source and destination differ, synchronization occurs.

Modification times are updated on the destination.

Permissions are preserved when the destination file does not exist; otherwise they remain unchanged.

Read permission on the source and write permission on the target are required.

Ownership cannot be preserved without appropriate privileges.

-t option

Synchronizes the modification time of source files to the destination, allowing rsync to skip unchanged files based on timestamps and size, though identical timestamps and size may miss content changes.

-I option

Disables the quick‑check algorithm, forcing a full file comparison to ensure data consistency at the cost of speed.

-v option

Increases verbosity; adding more "v" characters yields more detailed logs.

-z option

Compresses data during transfer, useful on slow networks; the algorithm is similar to gzip.

-r option

Enables recursive directory traversal, allowing whole directories to be synchronized.

-l option

Preserves symbolic links instead of following them; use -L to follow links instead.

-p option

Preserves file permissions regardless of whether the destination file already exists.

-g and -o options

Preserve group and owner information; changing these typically requires administrative rights.

-D option

Preserves device files (root only).

-a option

The archive option combines -rlptgoD, providing recursive transfer and preserving most attributes; it does not preserve hard links unless -H is added.

--delete, --delete-excluded, --delete-after options

Control deletion of files on the destination that no longer exist on the source; use with -r and optionally -n for a dry‑run.

--exclude and --exclude-from options

Exclude specific files or patterns from synchronization; --exclude-from reads patterns from a file.

--partial option

Enables resumable transfers; the combined -P flag is shorthand for --partial --progress.

--progress option

Shows transfer progress information.

Setting up an rsync server

An rsync daemon runs as a background service; clients can invoke rsync via scripts or crontab for automated synchronization.

Key configuration files:

/etc/rsyncd.conf – main daemon configuration

/etc/rsyncd.secrets – plain‑text user/password file (mode 600)

/etc/rsyncd.motd – welcome message displayed on login

rsyncd.conf example

# Minimal configuration file for rsync daemon
pid file = /var/run/rsyncd.pid
motd file = /etc/rsyncd.motd
port = 873
address = 192.168.20.24
uid = root
gid = root
use chroot = yes
read only = no
hosts allow = *
hosts deny = *
max connections = 5
log file = /var/log/rsync.log
transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300

[test]
path = /home/lcl/test
list = yes
ignore errors
auth users = lcl
secrets file = /etc/rsyncd.secrets
comment = lcl test
#exclude = samba/

The hosts allow directive specifies which client IPs may connect; hosts deny blocks others.

rsyncd.secrets

Stores usernames and passwords in plain text, one per line, e.g.:

lcl:12345

rsyncd.motd

Custom welcome message displayed to clients, for example:

+++++++++++++++++++++++++++++++++++++++ Welcome to use lcl rsync services! +++++++++++++++++++++++++++++++++++++++

Start the daemon with:

rsync --daemon

rsync command formats

Six common usage patterns:

Copy local files: rsync [OPTION]… SRC [SRC]… DEST Copy local to remote via SSH: rsync [OPTION]… SRC [SRC]… [USER@]HOST:DEST Copy remote to local via SSH: rsync [OPTION]… [USER@]HOST:SRC DEST Copy from remote rsync daemon to local: rsync [OPTION]… [USER@]HOST::SRC DEST Copy from local to remote rsync daemon: rsync [OPTION]… SRC [SRC]… [USER@]HOST::DEST Copy using rsync URL syntax: rsync [OPTION]… rsync://[USER@]HOST[:PORT]/SRC DEST Each mode is selected based on the presence and type of colon separators in the source or destination paths.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

OperationsLinuxBackupServer Configurationrsyncfile synchronization
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.