I decided to launch a new Amazon instance with CentOS 7 and install PHP 7 on it, to test  some WordPress themes/plugins on the new PHP version, however, I got stuck a little bit about how to copy my files from the old Amazon instance to the new one, in this blog I will record what exactly I did to get this job done, so in case anyone had the same situation…

  • While logged in the old instances, I generated RSA pair of keys, using this command:
    ssh-keygen -t rsa

    then specifying the location of the keys to be saved, this will generate two keys, key_name and key_name.pub

  • After that you will need to copy the content of key_name.pub file to the authorized ssh keys file in second instance, to allow connection between both of them, to do that, simply run this command on the first instance:
    sudo cat /path_to_key_name.pub

    Then copy the file content exactly, and proceed to the next step.

  • On the second instance, you will need to edit the ssh authorized keys file, by entering this command:
    sudo nano /home/your_user/.ssh/authorized_keys

    and paste the exact key_name.pub file content copied int he previous step.

  • After that you can test the ssh connection from your first instance to the second one, by entering this command on the first instance:
    sudo ssh -i /path_to_key_name your_user@second_instance_public_ip

    You should now be connected to the second instance, simply, type logout to exit and proceed to the next step.

  • From the first instance, we will use SCP command to copy files to the second instances, by entering something like this:
    sudo scp -i "/path_to_key_name" -r /path_to_what_you_want_to_copy your_user@second_instance_public_ip:/path_to_where_to_save_copied_files


  • Another faster way than SCP is using tar command as the following:
    sudo tar -c /path_to_what_you_want_to_copy | ssh -i "path_to_key_name" your_user@second_instance_public_ip 'tar -xvf - -C /path_to_where_to_save_copied_files'


That’s it, everything should work fine by following the same steps, however, there is something to take care about, which is the folder permissions on the second instances must allow others to write permissions, you can enable that temporarily by chmod 757 or 777 till you finish the copying process.