Appendix A. Using multiple SSH keys for different domains/projects

If you need to access multiple domains in the Red Hat Mobile Application Platform Hosted (RHMAP) as different users you need to use seperate SSH keys when accessing the Git repositories, since each SSH key can only be associated with a single user. You need to tell Git/SSH which key you want to apply to each host. Typically, you set this up using an SSH config file.

SSH normally attempts to use all the identity files available to it, and if several of your ssh keys are valid in the cluster, it may use one that is valid for the cluster but which does not have access to the project that you are trying to clone.

You can update your local SSH config file, normally ~/.ssh/config, to list the identities to use for a particular host, but you must also add an IdentitiesOnly yes clause, to tell SSH to only use the specified identity file for a particular host, rather than all the identity files.

For example, if you want to access App repositories as two different users, create SSH keys for each of the users, upload each SSH key to the corresponding user’s account.

In the example below, the SSH key file /Users/jbloggs/.ssh/key_for_domain1_id_rsa has been uploaded to the user in domain1.redhatmobile.com, and /Users/jbloggs/.ssh/key_for_domain2_id_rsa has been uploaded to the user in domain2.redhatmobile.com

To allow access to the App repositories:

git@domain1.redhatmobile.com:domain1/jbAdvTest-mmCord1.git
git@domain2.redhatmobile.com:domain2/jbAdvTest-mmCord2.git

Your ssh config file is similar to the following:

Host domain1.redhatmobile.com
HostName domain1.redhatmobile.com
IdentitiesOnly yes
IdentityFile /Users/jbloggs/.ssh/key_for_domain1_id_rsa
Host domain2.redhatmobile.com
HostName domain2.redhatmobile.com
IdentitiesOnly yes
IdentityFile /Users/jbloggs/.ssh/key_for_domain2_id_rsa

You can then clone the repos using the git commands:

git clone git@domain1.redhatmobile.com:domain1/jbAdvTest-mmCord1.git
git clone git@domain2.redhatmobile.com:domain2/jbAdvTest-mmCord2.git

Because of the ssh config file, the appropriate SSH key is used for each domain. For more information on the configuration of ssh, check the documentation for your local installation of SSH. Depending on your Operating System, it may be available from the command line man ssh_config.

Note

The configurations and domain names above are examples only and do not refer to actual domains.