Reputation: 96454
How can I set up my system so I can clone from both sources - github and aws CodeCommit - without making changes to switch between them each time?
Upvotes: 5
Views: 664
Reputation: 96454
Create or edit a ~/.ssh/config
file
Make the contents be:
Host git-codecommit.*.amazonaws.com
User APKAS2GIPODK7YOUR-ID
IdentityFile ~/.ssh/codecommit_rsa
Host github.com
User your_github_username
IdentityFile ~/.ssh/id_rsa
I am assuming you already have generated your github ssh keys as id_rsa
and id_rsa.pub
Generate your aws keys as follows to create the codecommit_rsa
files, i.e. different files from your github id_rsa
files
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/durrantm/.ssh/id_rsa): /home/durrantm/.ssh/codecommit_rsa
#
# **NOTE** As shown, change above filename from id_rsa to codecommit_rsa !!!
# This avoids over-writing your github id_rsa keys (so you can have both)
# So don't just press return for defaults !!!
#
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/durrantm/.ssh/codecommit_rsa.
Your public key has been saved in /home/durrantm/.ssh/codecommit_rsa.pub.
Now I can clone either repo
$ git clone ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/HellowBlueGreenWorld
Cloning into 'HellowBlueGreenWorld'...
remote: Counting objects: 6, done.
Receiving objects: 100% (6/6), 759 bytes | 759.00 KiB/s, done.
...
$ git clone [email protected]:durrantm/setups.git
Cloning into 'setups'...
remote: Enumerating objects: 9, done.
...
Receiving objects: 100% (1739/1739), 1.21 MiB | 4.52 MiB/s, done.
...
Upvotes: 2
Reputation: 1100
I prefer aliasing AWS codecommit repos, because I can't use multiple AWS accounts with just specifying Host.
My ~/.ssh/config file(where AWS account administrator has RW access, reader has R access):
# AWS - administrator
Host git-aws-administrator
Hostname git-codecommit.ap-northeast-2.amazonaws.com
User ABCDEFGHIJK
IdentityFile /Users/(username)/.ssh/id_rsa
# AWS - reader
Host git-aws-reader
Hostname git-codecommit.ap-northeast-2.amazonaws.com
User 123456789
IdentityFile /Users/(username)/.ssh/id_rsa
And when you clone your codecommit repository as administrator account, you clone with git clone ssh://git-aws-administrator/v1/repos/(reponame)
command. When you clone non-codecommit repository, you just clone it as usual.
Upvotes: 1