It is a basic necessity to move files between local devices or between two remote machines. There are many ways we can achieve that, and one of the safest and fastest methods is SCP. Using SCP (secure copy) files can securely copy data from one server to another server or between local hosts. It is based on the Secure Shell (SSH) protocol, which employs the same authentication and security. SCP is popular because of its ease of use, security, and pre-installed availability.

SCP uses the same port as SSH i.e., 22. If your company is using a cloud service provider, it’s potent to stay on top of security. There are many blogs online that helps you solve to copy data from a server to a local machine, here we are interested in showing you how you can copy data from one server to another.

Suppose you have two VPS, and one of them hosts your website. Due to some urgency, you need to backup or keep a copy of your certain data in the next instance. Backing up data is typical while working in cloud architecture. If you have a business or personal need to migrate data between servers, host emails, and servers, you can contact Cloudlaya for the best solution. Cloudlaya is one of the best cloud hosting companies in Nepal and emerging.

Stepwise Guide to Copy Data From One Server to Another

Copying files from one host to another can be critical thus, follow the following pictorial guide accordingly.

Step 1: Initially, we will require two VPS machines up and running. Here, we are using two AMI (Amazon Linux 2 AMI (HVM) – Kernel 5.10, SSD Volume Type) nearly based on CentOS viz:

  • Source VPS
  • Destination VPS

The setup should be fairly easy, however, make sure to use free tier VPS for demonstration purposes.

Securely Copy Data From One Server to Another Server

Step 2: Now, we use SSH to connect to these two instances. You might want to consider allocating the public IP of the instance with the Elastic IP so that the IP stays reserved and helps with fault tolerance.

Note: Keep the .pem file safe.

Furthermore, copy this command to connect to VPS respectively.

sudo ssh username@<PublicIP> -i /path-to/.pem key

SCP to transfer data between servers

Step 3: On the VPS1, create a text file which we will later copy to the destination (VPS2) host.

nano test.txt

Now add some text and then verify the content with the cat command.

cat test.txt

contet in VPS

Step 4:  Next, we need to copy the .pem content that is in our local machine to VPS1 so that we can use that secret key to connect to the second VPS.

cat ec2-test.pem

Here, copy the secret key in the clipboard.

Securely Copy Data From One Server to Another Server

Step 5: Now, as expected, create one file with the name ec2-two.pem in the VPS1 and paste the RSA key to the file.

RSA

Step 6: We are all set with a file to copy to the next server and we have Public IP and the secret key of the VPS2. Using the SCP command and specifying the source and destination locations we can easily copy data from one server to another.

sudo scp -i ec2-two.pem test.txt destination_username@destination_publicIP:

This copies test.txt to the home directory of the destination server. If you wish to create a directory in the destination server and copy the content, simply run the following command specifying the folder name.

usage: scp [-346BCpqrTv] [-c cipher] [-F ssh_config] [-i identity_file] [-J destination] [-l limit] [-o ssh_option] [-P port] [-S program] source ... target 

Now you should have a complete overview of SCP and how it works to securely copy data from one server to another.

Moving files around will be simple once we grasp how things operate. If you are looking to migrate servers, host email, and websites, you can contact Cloudlaya today for the best AWS hosting solution in Nepal.