How to Transfer File from One Server to Another in Linux?

If you handle enough Linux servers you are likely familiar with the SSH command that transfers files from one Linux server to another.

We are going to use Command Line Interface (CLI) for this purpose because different Linux distros have different Graphical User Interface, but same CLI. The process is somewhat simple-

- Log into the Linux server containing the files that you want to copy
- Type in the SCP file command to copy the file(s). The command has the following syntax - FILE USER@SERVER-IP:/DES-DIRECTORY

Where FILE is the actual file that you are copying, USER is the username, SERVER-IP is the IP address of the remote server and DES-DIRECTORY its Destination directory.

To transfer files between servers, you will need to constantly-

- Log into each server (If you are moving files between three servers, you will constantly be logging in an out of each).
- Open files and copy their destinations.
- Log out of the source machine

With the SCP command that we are going to discuss, you can make the above process more efficient. Put simply, you can log into just one Linux machine and start transferring files from one server to another, without logging in or out of them.

SSH Command

The SSH command provides an encrypted connection between two (or more) hosts even over an insecure, public network. This in turn can be used to establish terminal access to transfer files or tunnel apps to a device.

Tunneling is the process of securely connecting an application and a device over an open, unencrypted network.

Transferring Files Using the SSH Command

We will be transferring the file address /home/go4hosting/kb from a dummy IP 192.168.1.103 to another remote server with (dummy) IP 192.168.1.101, while on 192.168.1.102.

- Target machine's IP - 192.168.1.101
- Home machine's IP - 192.168.1.103
- Current machine's IP - 192.168.1.102

Assuming you already have your SSH keys generated, we will continue forward, copying all the SSH keys to and from these remote machines.

Execute the following commands-

- From 192.168.1.162 issue the command ssh-copy-id [email protected]
- From 192.168.1.162 issue the command ssh-copy-id [email protected]
- From 192.168.1.51 issue the command ssh-copy-id [email protected]
- From 192.168.1.53 issue the command ssh-copy-id [email protected]

This will copy SSH keys to all the machines. You can log into each machine and check whether key authentication is working.

Once done, you are ready to send kb hosted on .103 to .101 from .102.

Make sure you have logged into the machine with IP ending .103.

Now shoot the given command-

scp -3 [email protected]:/home/go4hosting/kb
[email protected]:/home/go4hosting/kb

We have already setup the authentication key so you shouldn't be prompted for a password. Wait for the command to finish. It may take a few seconds or several minutes depending upon your file size.

Congrats, you have successfully copied the file between two servers without even logging into any of them.

Was this answer helpful? #8 #6
 

Did We Miss Out on Something?

Relax, we have you covered. At Go4hosting, we go the extra mile to keep our customers satisfied. We are always looking out for opportunities to offer our customers “extra” with every service. Contact our technical helpdesk and we’d be more than happy to assist you with your Cloud hosting, Colocation Server, VPS hosting, dedicated Server or reseller hosting setup. Get in touch with us and we’d cover all your hosting needs, however bizarre they might be.

Submit your Query

  • I'm not a robot

Browse by ServicesBrowse by Services

Resource Library

What is Cloud Computing

Understand the term cloud computing, the ongoing trend, its playing field, future growth and how industry...

Myths about Cloud Computing

Cloud computing, in the recent years, has become a subject of significant discussion among the industry experts.

Download Now

Did We Miss Out on Something?

Relax, we have you covered. At Go4hosting, we go the extra mile to keep our customers satisfied. We are always looking out for opportunities to offer our customers “extra” with every service. Contact our technical helpdesk and we’d be more than happy to assist you with your Cloud hosting, Colocation Server, VPS hosting, dedicated Server or reseller hosting setup. Get in touch with us and we’d cover all your hosting needs, however bizarre they might be.

Submit Query

Please fill in the form below and we will contact you within 24 hours.