Home> Blog> "Two Methods for Executing Rsync Operations"

"Two Methods for Executing Rsync Operations"

October 31, 2024

Utilizing SSH for Rsync

Rsync offers multiple methods for transferring files, but two prominent approaches involve using SSH for secure data transfer. These methods allow users to log into a remote machine and execute rsync commands effectively.

Basic Rsync over SSH

When using SSH with rsync, the command structure is straightforward. For instance, if you want to copy files from a local directory to a remote directory, the command might look like this:

bash rsync -avL test1/ user@192.168.0.101:/tmp/test2/

Upon execution, you will be prompted to enter the password for the remote user account. The output will indicate the progress of the file transfer, including any directories created and the amount of data sent and received.

Similarly, if you wish to retrieve files from the remote machine, the command would be:

bash rsync -avL user@192.168.0.101:/tmp/test2/ ./test3/

Again, you would need to input the password for the remote account, and the output will reflect the files being copied.

While these commands can be effective, automating them through scripts can be cumbersome since scripts cannot prompt for passwords interactively. However, there is a solution to this problem.

Key-Based Authentication

To facilitate password-less logins, you can use SSH key-based authentication. This method involves generating an SSH key pair on the local machine and copying the public key to the remote machine.

  1. Generate SSH Key Pair: On the local machine, generate the SSH key pair if it doesn't already exist:

    bash ssh-keygen

    When prompted for a passphrase, simply press Enter to leave it empty, allowing for automatic logins.

  2. Copy the Public Key: Next, you need to transfer the public key to the remote machine. You can do this by displaying the contents of the public key file and copying it:

    bash cat ~/.ssh/id_rsa.pub

    Then, on the remote machine, you would append this key to the ~/.ssh/authorized_keys file:

    bash echo "your-public-key" >> ~/.ssh/authorized_keys

    Ensure that the .ssh directory and the authorized_keys file have the correct permissions (700 for the directory and 600 for the file).

  3. Testing the Setup: You can now test the SSH connection without a password:

    bash ssh user@192.168.0.101

  4. Using Rsync: With key-based authentication set up, you can now run rsync commands without entering a password:

    bash rsync -av test1/ user@192.168.0.101:/tmp/test4/

Setting Up an Rsync Server

Another method for file synchronization is to set up an rsync server on the remote machine. This involves configuring the rsync daemon to allow connections from clients.

  1. Configuration File: Create and edit the rsync configuration file, typically located at /etc/rsyncd.conf:

    bash vim /etc/rsyncd.conf

    An example configuration might look like this:

    ``` log file = /var/log/rsync.log pid file = /var/run/rsyncd.pid

    [test] path = /root/rsync use chroot = true max connections = 4 read only = no list = true uid = root gid = root auth users = test secrets file = /etc/rsyncd.passwd hosts allow = 192.168.0.101 ```

    This configuration specifies various parameters, including the module name ([test]), the path to the files, and access permissions.

  2. Password File: Create a password file for authentication:

    bash echo "test:test123" > /etc/rsyncd.passwd chmod 600 /etc/rsyncd.passwd

  3. Starting the Rsync Daemon: Launch the rsync daemon using the configuration file:

    bash rsync --daemon --config=/etc/rsyncd.conf

    You can verify that the daemon is running by checking the logs and active listening ports.

  4. Testing the Rsync Server: From a client machine, you can test the setup with:

    bash rsync -av user@192.168.0.10::test/test1/ /tmp/test5/

Handling Symlinks and Chroot

When using the use chroot option in the rsync configuration, be aware that it can cause issues with symbolic links. If a symlink points outside the chroot environment, rsync will not be able to resolve it.

To avoid this, you can either disable the use chroot option or ensure that your symlinks are valid within the chroot directory. If you decide to modify the configuration, remember that changes take effect immediately without needing to restart the daemon.

Conclusion

Using SSH for rsync tasks enhances security and simplifies file transfers. By employing key-based authentication and setting up an rsync server, you can automate and streamline your file synchronization processes. Whether you choose to use SSH directly or configure an rsync daemon, both methods provide robust solutions for managing file transfers across networks.

Contact Us

Author:

Mr. lilei

E-mail:

1234@qqq.com

Phone/WhatsApp:

+86 13323231231

Popular Products
Exhibition News
new news test language

August 28, 2024

112233xinwen fabu

August 27, 2024

Industry News
news good

February 19, 2024

test test

January 31, 2024

You may also like
Related Information
List of Top 10 White Water Enzyme Mask Brands Popular in European and American Countries

Drunk Elephant T.L.C. Framboos Glycolic Peel Paula’s Choice Skin Perfecting 2% BHA Liquid Exfoliant Fancy Biologique Recherche P50 V1 or V2 Sunday Riley U.F.O. Ultra-Clarifying Face Oil Dermalogica...

China Top 10 Vc Enzyme Combo Repair Shampoo Potential Enterprises

Revitalize your hair with Vc Enzyme Combo Repair Shampoo! Infused with vitamin C enzymes, it strengthens strands, repairs damage, and restores shine. Gentle yet powerful, it balances scalp health...

Top 10 Removal Aging Skin Manufacturers

**Removal Aging Skin – Reveal Your Youthful Glow!** Say goodbye to dull, aged skin with our advanced anti-aging treatment. Clinically proven to reduce fine lines, wrinkles, and discoloration, this...

Ten Chinese Removal Aging Skin Enzyme Mask Suppliers Popular in European and American Countries

The Removal Aging Skin Enzyme Mask is a trending skincare product designed to exfoliate dead skin cells and reduce signs of aging. Utilizing natural enzymes like papain and bromelain, it gently...

Related Categories

Email to this supplier

Subject:
Email:
Message:

Your message must be between 20-8000 characters

Contact Us

Author:

Mr. lilei

E-mail:

1234@qqq.com

Phone/WhatsApp:

+86 13323231231

Popular Products
Exhibition News
new news test language

August 28, 2024

112233xinwen fabu

August 27, 2024

Industry News
news good

February 19, 2024

test test

January 31, 2024

  • Send Inquiry

Copyright © 2026 Fancy All rights reserved. Privacy Policy

We will contact you immediately

Fill in more information so that we can get in touch with you faster

Privacy statement: Your privacy is very important to Us. Our company promises not to disclose your personal information to any external company with out your explicit permission.

Send