TRANSFERING FILES FROM ONE EC2 INSTANCE TO ANOTHER
- First, we need to make sure that both the instance is created using the same key-pair
- Then after making sure that the both the instance are made from the same key-pair, you have to store the private keypair in the instance so the instance can do the transferring of the file .
- For storing the private key on the instance you have to open the .pem file that is stored in your local device and then you will get some content like this
- Then you must create a file inside the “~/.ssh” directory using the “touch yourfilename.txt”
- Then you have to open the file using the editor “vi yourfilename.txt”
- Here you will paste the data that you got using the step number 3
- Now you have to run the command “rsync -avz –delete -e "ssh -i ${KEY_FILE}" "${SOURCE_DIR}" ${DESTINATION_USER}@${DESTINATION_HOST}:${SOURCE_DIR}”
${KEY_FILE}-The path where your public key is stored
${SOURCE_DIR}-The path to the source From where you need to copy
${DESTINATION_USER}-the user name of the destination instance
${DESTINATION_HOST}-The IP address of the destination instance
:${DESTINATION_DIR}-The destination path where you want you files to be copied
Example-(rsync -avz --delete -e "ssh -i /home/ubuntu/.ssh/new-test-kp.pem" "/home/ubuntu" ubuntu@172.31.10.186:/home/ubuntu)
- After running this command you will gwt an output like this
- With this the transferring of the files is successfully completed.