Rsync is a robust utility used frequently in Linux environments for copying and synchronizing files and directories between two locations. It offers numerous options for synchronization and preservation of files and is cherished for its speed and versatility. To copy files between two servers without a password, we need to combine the capabilities of Rsync and SSH (Secure Shell).
First, ensure that Rsync is installed on both servers. If not, it can be installed with the following commands:
- On a Ubuntu/Debian server: `sudo apt-get install rsync`
- On a CentOS/RHEL server: `sudo yum install rsync`
Next, consider the server you wish to pull/push the files from as the Source server, and the one you wish to push/pull the files to as the Destination server.
The main requirement for passwordless transfer is setting up SSH keys between the two servers. This involves generating a public-private key pair on the Source server and copying the public key to the Destination server.
Here’s how to do that:
- Login to the Source server.
- Create an SSH key pair with the following command: `ssh-keygen -t rsa`
- When prompted to “Enter file in which to save the key”, press Enter to accept the default location.
- When asked to “Enter passphrase”, hit Enter for no passphrase. Note that this is not recommended for production environments due to security reasons.
- Copy the public SSH key to the Destination server with this command: `ssh-copy-id -i ~/.ssh/id_rsa.pub user@destination_server`, where `user` is your username and `destination_server` is the hostname or IP address of the Destination server.
Now SSH connection from Source to Destination server won’t require a password.
To use Rsync without password:
- On the Source server, use the following command:
`rsync -avz /source/directory/ user@destination_server:/destination/directory/`
In this command:
- `a` stands for archive mode.
- `v` increases verbosity.
- `z` compresses data during transfer which increases speed.
- `/source/directory/` is path of the data on the Source server.
- `user@destination_server:/destination/directory/` is the path where you want to move the data on the Destination server.
You can also automate this syncing process by putting this command into a cron job.
Sources:
- George Ornbo (2014). “SSH, The Secure Shell: The Definitive Guide”.
- HD Moore (2011). “Metasploit: The Penetration Tester’s Guide”.
- K Asghar (2008). “Linux Administration: A Beginners Guide”.