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-
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-
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?
9
10