How to use rsync for remote sync?

QuestionsQuestions8 SkillsProBasic Files OperationsOct, 06 2025
0132

To use rsync for remote synchronization, you can specify the remote server's address in the command. Here’s the general syntax:

rsync [options] source/ user@remote_host:/path/to/destination/

Example Usage

  1. Syncing Local to Remote: To sync a local directory to a remote server, use:

    rsync -avz /path/to/local/dir/ user@remote_host:/path/to/remote/dir/
    • -a: Archive mode (preserves permissions, timestamps, etc.)
    • -v: Verbose output
    • -z: Compresses data during transfer
  2. Syncing Remote to Local: To sync a remote directory to your local machine, use:

    rsync -avz user@remote_host:/path/to/remote/dir/ /path/to/local/dir/

Additional Options

  • Delete: To delete files in the destination that are not present in the source, add the --delete option:

    rsync -avz --delete /path/to/local/dir/ user@remote_host:/path/to/remote/dir/
  • Dry Run: To see what would be transferred without actually doing it, use the --dry-run option:

    rsync -avz --dry-run /path/to/local/dir/ user@remote_host:/path/to/remote/dir/

Authentication

When using rsync with a remote server, you may need to provide a password for the user account on the remote server. Alternatively, you can set up SSH keys for passwordless authentication.

Example with SSH

If you want to specify a different SSH port, you can do so with the -e option:

rsync -avz -e 'ssh -p 2222' /path/to/local/dir/ user@remote_host:/path/to/remote/dir/

Replace 2222 with your desired SSH port.

0 Comments

no data
Be the first to share your comment!