To set up rsync
for transferring files between local and remote systems, follow these steps:
rsync
rsync
is usually pre-installed on most Linux distributions, but if it’s not, you can install it using your package manager.
sudo apt update
sudo apt install rsync
sudo yum install rsync
sudo dnf install rsync
sudo pacman -S rsync
rsync
often uses SSH to securely transfer files between systems. Make sure SSH is set up on both the local and remote machines.
# On Debian/Ubuntu
sudo apt install openssh-server
# On Red Hat/CentOS
sudo yum install openssh-server
# On Fedora
sudo dnf install openssh-server
# On Arch Linux
sudo pacman -S openssh
Enable and start the SSH service:
sudo systemctl enable ssh
sudo systemctl start ssh
You can test SSH by connecting to the remote machine:
ssh user@remote_ip
For password-less, secure connections, you can generate an SSH key pair and add the public key to the remote server.
ssh-keygen -t rsa -b 4096
After generating, copy the key to the remote server:
ssh-copy-id user@remote_ip
Now, you can SSH into the remote machine without needing to input the password every time.
rsync
for File Transferrsync -avz /path/to/local/dir/ user@remote_ip:/path/to/remote/dir/
-a
: Archive mode to preserve file attributes.-v
: Verbose output.-z
: Compress data during transfer./path/to/local/dir/
: The source directory.user@remote_ip:/path/to/remote/dir/
: The destination on the remote server.rsync -avz user@remote_ip:/path/to/remote/dir/ /path/to/local/dir/
To ensure the destination is an exact copy of the source, including deleting files that no longer exist in the source:
rsync -avz --delete /path/to/local/dir/ user@remote_ip:/path/to/remote/dir/
You can automate the syncing process using cron
to schedule regular backups or transfers.
crontab -e
0 2 * * * rsync -avz /path/to/local/dir/ user@remote_ip:/path/to/remote/dir/
This will automatically run the rsync
command at 2 AM every day.
Do you need help or support for RSync? Feel free to contact us!