Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AWS CodeCommit Multiple Account Config
# This file is: ~/.ssh/config
# You may have other (non-CodeCommit) SSH credentials stored in this
# config file – in addition to the CodeCommit settings shown below.
# NOTE: Make sure to run [ chmod 600 ~/.ssh/config ] after creating this file!
# Credentials for Account1
Host awscc-account1 # 'awscc-account1' is a name you pick
Hostname git-codecommit.us-east-1.amazonaws.com # This points to CodeCommit in the 'US East' region
User A1EXAMPLE01234567891 # UserID as provided by IAM Security Credentials (SSH)
IdentityFile ~/.ssh/account1-awsCC-rsa # Path to corresponding key file
# Credentials for Account2
Host awscc-account2
Hostname git-codecommit.us-east-1.amazonaws.com
User A2EXAMPLE01234567892
IdentityFile ~/.ssh/account2-awsCC-rsa
# Credentials for Account3
Host awscc-account3
Hostname git-codecommit.us-east-1.amazonaws.com
User A3EXAMPLE01234567893
IdentityFile ~/.ssh/account3-awsCC-rsa
@justinpawela

This comment has been minimized.

Copy link
Owner Author

@justinpawela justinpawela commented Aug 3, 2016

AWS CodeCommit Multiple Account Config

This doc shows how to set up Git repos and SSH to allow the use of CodeCommit with more than one AWS account. This applies to macOS/Linux/Unix.

Initial Setup

Follow the SSH setup steps from the CodeCommit Docs, but be sure to configure ~/.ssh/config as shown in this Gist.

If your config file is already configured as in the docs, feel free to update it, but you'll have to change the remote settings of any repos you've already cloned (see "Updating an Existing Repo" below).

Cloning a Repo

When newly cloning a repo, make the following change to your clone command:

_ _
Command git clone ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/my-repo
Becomes git clone ssh://awscc-account1/v1/repos/my-repo

where awscc-account1 should be the name chosen on the Host line of the corresponding account in ~/.ssh/config.

Updating an Existing Repo

When working with a repo that is already cloned to your local machine, make the same change in: /path/to/my-repo/.git/config

In the [remote "origin"] section, update the url as shown above in "Cloning a Repo".


Hats off to: DavidJ@AWS for this tip!

@agmezr

This comment has been minimized.

Copy link

@agmezr agmezr commented Feb 9, 2018

Or you can also use git remote set-url origin <new-url> to update an existing repo

@Dzhuneyt

This comment has been minimized.

Copy link

@Dzhuneyt Dzhuneyt commented Aug 5, 2019

Amazing work! I wish AWS CodeCommit provided a simpler way to approach this (e.g. by including the repo name inside the hostname instead of path, so that we can define multiple keys per repo).

@LiutongZhou

This comment has been minimized.

Copy link

@LiutongZhou LiutongZhou commented May 28, 2020

Nice gist

@utahcon

This comment has been minimized.

Copy link

@utahcon utahcon commented Jun 17, 2020

Thanks, this really helped me!

@edonosotti

This comment has been minimized.

Copy link

@edonosotti edonosotti commented Nov 6, 2020

Kudos!

@damien-monni

This comment has been minimized.

Copy link

@damien-monni damien-monni commented Nov 10, 2020

Thank you!

@mouradhamoud

This comment has been minimized.

Copy link

@mouradhamoud mouradhamoud commented Dec 5, 2020

Thank you!!

@lflfm

This comment has been minimized.

Copy link

@lflfm lflfm commented Jan 7, 2021

Thank you!!

@seifolah-ghaderi

This comment has been minimized.

Copy link

@seifolah-ghaderi seifolah-ghaderi commented Apr 26, 2021

Thanks.

@andreashe

This comment has been minimized.

Copy link

@andreashe andreashe commented Sep 24, 2021

Cool! i love it! And bookmarked. I also suggested this to AWS to be adapted to their docs.

@dfravel

This comment has been minimized.

Copy link

@dfravel dfravel commented Sep 27, 2021

still works perfectly! thank you so much for keeping this live. it's a simple solution to a frustrating problem.

@badfun

This comment has been minimized.

Copy link

@badfun badfun commented Oct 26, 2021

Excellent. So much better than commenting out all the time. Cheers!

@lonmiller

This comment has been minimized.

Copy link

@lonmiller lonmiller commented Nov 23, 2021

Added update due to OpenSSH deprecating support for ssh-rsa. New flags are needed to connect with CodeCommit until they get the certificates updated. Changes in forked gist at https://gist.github.com/lonmiller/6f6c00400bf627642a3696dc575d2e6b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment