1.We need to set three Virtual Machines that’s easy you can see the related tutorial on youtube.
Now the thing is we need to ssh from host(my physical machine) to the guest(master VM) and from the master VM to the two mirror VMs without using password. For that we need IP of the VMs. So the plan is to create two NICs, one NIC is connected to NAT, and the second NIC is connected to vboxnet0 through Host-Only. First we go to File->Preferences setting in Virtual Box and then Network->Host Only Networks add a new network. Then we need to make sure that all the VMs are connected to two Ethernet interfaces.
If you are using any server distribution on your VM you need to add the new network in the file /etc/network/interfaces.
That’s it now you have the IP to ssh.
2.Install openssh-client on the host machine and openssh-server on the master VM and two mirror VM’s .
Generate two RSA-4096 keypairs – one on the host machine, one on the master server using the command ssh-keygen -t rsa -b 4096
Set up the master server with the public key of your host machine, and set up the mirrors with the public key of the master machine so we can use ssh-copy-id -i ~/.ssh/id_rsa.pub user@IP and to ssh without password we need to change the permission of .ssh/authorized_keys and add the private key identities to the authentication agent, use ssh-add
3.Set up git server on all the three VMs, first sudo apt-get install git-core on all the three servers then create bare repository first cd into the git repository then git –bare init and set up post-update hook. For that you need to create a post-update file in which we write the bash script to push the changes to the mirror servers. The contents of the post-update file on the master git server .
As we see here we have used git push –mirror url command which pushes the committed changes to the specified mirror url from the master server to the two mirror servers.
We can now clone the repository from the master to our host machine and can push the commits and we have the changes in the mirror servers as well.
You can also check using a different branch to commit changes and then check that the changes are reflected on both the mirror git servers.