How to Use rsync and scp Commands in Reverse Mode on Linux

Typically, you use the rsync command or scp command to copy files from one server to another.

But if you want to perform these commands in reverse mode, how do you do that?

Have you tried this? Have you had a chance to do this?

Why would you want to do that? Under what circumstances should you use it?

Scenario-1: When you copy a file from “Server-1” to “Server-2”, you must use the rsync or scp command in the standard way.

Also, you can do from “Server-2” to “Server-1” if you need to.

To do so, you must have a password for both systems.

Scenario-2: You have a jump server and only enabled the ssh key-based authentication to access other servers (you do not have the password for that).

In this case you are only allowed to access the servers from the jump server and you cannot access the jump server from other servers.

In this scenario, if you want to copy some files from other servers to the jump server, how do you do that?

Yes, you can do this using the reverse mode of the scp or rsync command.

General Syntax of the rsync and scp Command:

The following is a general syntax of the rsync and scp commands.

rsync: rsync [Options] [Source_Location] [Destination_Location]

scp: scp [Options] [Source_Location] [Destination_Location]

General syntax of the reverse rsync and scp command:

The general syntax of the reverse rsync and scp commands as follows.

rsync: rsync [Options] [Destination_Location] [Source_Location]

scp: scp [Options] [Destination_Location] [Source_Location]

1) How to Use rsync Command in Reverse Mode with Standard Port

We will copy the “2daygeek.tar.gz” file from the “Remote Server” to the “Jump Server” using the reverse rsync command with the standard port.

# rsync -avz -e ssh [email protected]:/root/2daygeek.tar.gz /root/backup
The authenticity of host 'jump.2daygeek.com (jump.2daygeek.com)' can't be established.
RSA key fingerprint is 6f:ad:07:15:65:bf:54:a6:8c:5f:c4:3b:99:e5:2d:34.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'jump.2daygeek.com' (RSA) to the list of known hosts.
[email protected]'s password:
receiving file list ... done
2daygeek.tar.gz

sent 42 bytes  received 23134545 bytes  1186389.08 bytes/sec
total size is 23126674  speedup is 1.00

You can see the file copied using the ls command.

# ls -h /root/backup/*.tar.gz
total 125M
-rw-------   1 root root  23M Oct 26 01:00 2daygeek.tar.gz

2) How to Use rsync Command in Reverse Mode with Non-Standard Port

We will copy the “2daygeek.tar.gz” file from the “Remote Server” to the “Jump Server” using the reverse rsync command with the non-standard port.

# rsync -avz -e "ssh -p 11021" [email protected]:/root/backup/weekly/2daygeek.tar.gz /root/backup
The authenticity of host '[jump.2daygeek.com]:11021 ([jump.2daygeek.com]:11021)' can't be established.
RSA key fingerprint is 9c:ab:c0:5b:3b:44:80:e3:db:69:5b:22:ba:d6:f1:c9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[jump.2daygeek.com]:11021' (RSA) to the list of known hosts.
[email protected]'s password:
receiving incremental file list
2daygeek.tar.gz

sent 30 bytes  received 23134526 bytes  1028202.49 bytes/sec
total size is 23126674  speedup is 1.00

3) How to Use scp Command in Reverse Mode on Linux

We will copy the “2daygeek.tar.gz” file from the “Remote Server” to the “Jump Server” using the reverse scp command.

# scp [email protected]:/root/backup/weekly/2daygeek.tar.gz /root/backup

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

Your email address will not be published. Required fields are marked *