Let’s say you have your own GIT repository on one AMI. You want to communicate with it from another AMI. In this example, you want to clone the repository. Also, for this example, you are able to login to both AMIs and have public and private keys for both. The repository is located in /var/git/clientXYZ.git. Your public key file is named myPKfile.pem.
The GIT AMI has an elastic IP address associated with it (e.g. 23.1.2.3) and it is running Ubuntu. If it wasn’t an AMI, you could enter a commend like this:
git clone ssh://username@23.1.2.3/var/git/clientXYZ.git to get the information.
This git clone command will not work on the AMI. Instead, you should create the following file: ~.ssh/config and add the following lines
Host gitserver
Hostname 23.1.2.3
User ubuntu
IdentityFile ~/.ssh/myPKfile.pem
The assumption is the the myPKfile.pem file is already in the .ssh directory. Also, instead of gitserver, you can use any nickname you’d like.
Once you have this set up, you can then enter this to clone the directory:
git clone ssh://gitserver/var/git/clientXYZ.git
Bonus: you can also ssh gitserver to get to the other AMI
For more good details, see Custom identity file (id_rsa.pub) with git client / Dev-Articles / DracoBlue.