Migrating instances

This is a fast solution that should never be performed for a production environment.

In this tutorial, a source virtual machine will be migrated by copying all files to the destination virtual machine.


The following will be accomplished:

  1. Setup SSH on destination instance to allow root access.
  2. Install screen to ensure uninterrupted copying.
  3. Copy all necessary files from source to destination instance.


Perform the following:

  • Create a new instance with the same OS as the source's instance
  • SSH into the destination instance
  • Edit SSH configuration to allow root login
sudo vim /etc/ssh/sshd_config  

Look for PermitRootLogin and remove the # character, or for short perform this: /Permit [Enter] [i] [Remove hash]

  • Restart SSH service
# Redhat
sudo service ssh restart  
# Debian
sudu service sshd restart  
  • Set a password for root user
sudo passwd root  

You will be prompted to enter password twice.

  • SSH to destination instance with root credentials in another terminal to make sure you have root access
ssh root@<destination-address>  
  • SSH to your source instance

  • Create a new file called excludes.conf with the following contents:


Add all other folders that you do not wish to migrate such as log files.

  • Install screen to be able to continue with the migration process should your SSH connection fail
# Redhat
sudo yum install screen -y  
# Debian
sudu apt-get install screen  
  • Start the migration process
sudo rsync -azPx --exclude-from="excludes.conf" / root@<ip-address>  
  • Restart destination instance.

  • Remove the SSH key used for the destination's VM as it now uses the source's VM SSH credentials.

ssh-keygen -R <ip-address>  
  • SSH again to destination instance.

All should be working fine.

Zaid Daba'een

A traveller and an entrepreneur. Making wireless charging smart. UK Exceptional Talent. Interned at @NASA.