How to setup SSH configuration for AWS CodeCommit in your Linux/Mac system for same region with Multiple accounts.

When we are working in multiple projects, there is sure chance that we must have to use different AWS accounts. This makes a problem when we setup SSH configurations for same region.

For example if we set SSH Public key for account, when we tried to checkout a repository in the same region for another AWS account, there will be a conflict with the credentials.

To avoid conflicts in ssh config with multiple accounts in same region we can add two different configurations by creating two different public keys

Host git-codecommit.eu-west-1.amazonaws.com
  User APKXXRRTTTTTTBBVV
  IdentityFile ~/.ssh/id_rsa

Host git-codecommit.account2.amazonaws.com
    Hostname git-codecommit.eu-west-1.amazonaws.com
    User APKXXRRTTTTTTUUUU
    IdentityFile ~/.ssh/id_rsa_account2

We must have to generate two different Public/Private key and set those keys in CodeCommit credentials section

You can create keys with different emails like below

ssh-keygen -t rsa -C vimson@xxxxccccbbb.com

In the above example, we used a mixed example, one use direct host name and other as an alias. While doing operations in Theme2, we can use the following command.

git clone ssh://git-codecommit.account2.amazonaws.com/v1/repos/<repository_name>

Means Hostname should be replaced with the name you have given in the ssh config.