Im having the following issue. As part of my job, I handle multiple AWS Accounts, each of which have a separate AWS CodeCommit repos and account-specific IAM Users (which result on different User IDs)
I want to find a way that I can config my ssh to access different accounts depending on the repo
Currently it works correctly, as my config file looks like this:
Host git-codecommit.*.amazonaws.com
User APKAEIBAERJR2EXAMPLE
IdentityFile ~/.ssh/codecommit_rsa
What I need, is to be able to add different repos that use different accounts so that I don't have to edit the config file everytime I switch from one project to another i.e.
#Use this User ID and ssh-key for repo A
Host git-codecommit.*.amazonaws.com
User IAMUSERIDFROMACCOUNT1
IdentityFile ~/.ssh/codecommit_rsa
#Use this User ID and ssh-key for repo B
Host git-codecommit.*.amazonaws.com
User IAMUSERFROMANOTHERAWSACCOUNT
IdentityFile ~/.ssh/codecommit_rsa
I have browsed everywhere without finding the right answer. Thanks in advance for any help on this topic.
Regards
To change a CodeCommit repository's nameRun the update-repository-name command, specifying: The current name of the CodeCommit repository (with the --old-name option). To get the CodeCommit repository's name, run the list-repositories command. The new name of the CodeCommit repository (with the --new-name option).
Git credentials, an IAM-generated user name and password pair you can use to communicate with CodeCommit repositories over HTTPS. SSH keys, a locally generated public-private key pair that you can associate with your IAM user to communicate with CodeCommit repositories over SSH.
You are on the right track :-). You need to modify your config file and make a Host entry for each User/IdentityFile pair. For example:
Host git-account1
User IAMUSERIDFROMACCOUNT1
IdentityFile ~/.ssh/codecommit
HostName git-codecommit.us-east-1.amazonaws.com
Host git-account2
User IAMUSERIDFROMACCOUNT2
IdentityFile ~/.ssh/codecommit
HostName git-codecommit.us-east-1.amazonaws.com
Host git-account3
User IAMUSERIDFROMACCOUNT3
IdentityFile ~/.ssh/codecommit
HostName git-codecommit.us-east-1.amazonaws.com
Your git command lines would look like this:
git clone ssh://git-account1/v1/repos/AccountOneRepo
git clone ssh://git-account2/v1/repos/AccountTwoRepo
git clone ssh://git-account3/v1/repos/AccountThreeRepo
This worked for me.
You need to change SSH Key ID. SSH Kye ID you can get from IAM Users -> select_user -> security_credentials-> SSH Key ID
file name ~/.ssh/config
Host git-codecommit.ap-south-1.amazonaws.com
User <SSH Key ID>
IdentityFile ~/.ssh/id_rsa
HostName git-codecommit.ap-south-1.amazonaws.com
Host git-codecommit.us-east-2.amazonaws.com
User <SSH Key ID>
IdentityFile ~/.ssh/id_rsa
HostName git-codecommit.us-east-2.amazonaws.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With