How To Copy Files From One Linux Server To Another Using Rsync

In this tutorial we will be using Rsync to copy a file on Linux ServerA to Linux ServerB over SSH using two CentOS servers.

To begin we recommend you setup SSH keys between the two servers. To do this you can follow our below tutorials though is not required :

First lets make sure RSYNC is installed.

yum install rsync

Ok now that we have confirmed rsync is installed lets copy a file from one server to another using it.

In the different options provided we will assume the below:

Server A (local server that we are logged into): 10.10.10.1
Server B (remote server): 10.10.10.2

Option 1: Copy a file from a remote server to the local server

rsync -v -e ssh root@10.10.10.2:/home/test.txt /home

The command above will copy the file test.txt from the remote server to our local server in the folder /home.

The output should look similar :

# rsync -v -e ssh root@10.10.10.2:/home/test.txt /home
root@10.10.10.2's password:
test.txt

sent 30 bytes  received 73 bytes  22.89 bytes/sec
total size is 0  speedup is 0.00

**NOTE : If your server uses a different SSH port then 22, then you would use the command below. **

rsync -v -e 'ssh -p1070' root@10.10.10.2:/home/test.txt /home

Option 2: Copy a file from a local server to the remote server

rsync -v -e ssh /home/test.txt root@10.10.10.2:/home

The command above will copy the file test.txt from the local server to our remote server in the folder /home.

The output should look similiar :

# rsync -v -e 'ssh -p2222' /home/test.txt root@10.10.10.2:/home
root@10.10.10.2's password:
test.txt

sent 68 bytes  received 31 bytes  18.00 bytes/sec
total size is 0  speedup is 0.00

**NOTE : If your server uses a different SSH port then 22, then you would use the command below. **

rsync -v -e 'ssh -p2222' /home/test.txt root@10.10.10.2:/home

Wayne Egerer

Leave a Reply