How to Set up Daul-Authentication to GitHub and AWS CodeCommit

Both GitHub and AWS CodeCommit are used to version-control your source code. I use GitHub to share my code with the wider community and CodeCommit for production code for AWS. You may use other source control systems like BitBucket. Whatever the choice you make, it is convenient to set up your local machine to commit code to multiple Git-like code repositories.

In this post, I will show you how to set up dual-authentication to GitHub and AWS CodeCommit repositories. You can pretty much use the same way to set up Git connections to other tools. At work, I do the dual-authentication to CodeCommit and BitBucket in the same way.

Prerequisite

We assume you have AWS and BitBucket account and of course Git installed.

Steps

(1) Create SSH keys for both GitHub and CodeCommit. Use the online documentation here for GitHub and here for CodeCommit.

(2) Each SSH key pair will be created in the .ssh directory (usually located in your home directory). Name the keys so that you can differentiate them. Then, create config file as below.

(3) In the config file, you can define hosts, user ids and the paths to the private keys as below. For CodeCommit, user can be retrieved from the management console as described here. For GitHub, user is the user name.

# AWS Code Commit
Host git-codecommit.*.amazonaws.com
  User you-user-id
  IdentityFile ~/.ssh/codecommit_rsa
# Default GitHub
Host github.com
  HostName github.com
  User your-user-name
  IdentityFile ~/.ssh/id_rsa_git

(4) Create a repository named test_github in GitHub and test_codecommit in CodeCommit. Using UI is the easiest for GitHub. For CodeCommit, you can run AWS CLI command as below.

aws codecommit create-repository ^
--repository-name test_codecommit ^
--repository-description "test_codecommit"

(5) You can check the authentication in each system.

ssh -T git@github.com
ssh git-codecommit.(your aws region).amazonaws.com

(6) Let’s test by running the script below.

BitBucket

mkdir test_github
cd test_github
touch test.txt
echo hellogithub >> test.txt
git init
git add *
git status
git commit -m "git hub connectivity check"
git remote add origin git@github.com:(your username)/test_github
git push origin master

CodeCommit

mkdir test_codecommit
cd test_codecommit
touch test.txt
echo hellocodecommit >> test.txt
git init
git add *
git status
git commit -m "git hub connectivity check"
git remote add origin ssh://git-codecommit.(your region).amazonaws.com/v1/repos/test_codecommit
git push origin master

You can see the file is committed to the remote branches for both. Yay!

DBA
How to Manually Create Database Backup for SQL Server

Occasionally, I need to create a database backup from SQL Server manually on demand. It is a handy thing to know. Once the backup is created, it can be loaded to other SQL Server. This often happens when a developer wants to get the database from other environment or even …

DBA
How to Restore AdventureWorks to SQL Server Express

Once you have SQL Server Express installed on your local machine, you may want to load some example data so that you can play around with it. After all, what’s good with the database without data! MySQL comes with the Sakila database upon installation. SQL Server’s equivalent would be AdventureWorks …

DBA
How to Connect to Locally Installed SQL Server Express with JDBC

Once you install SQL Server Express locally, you need to go through a few configuration steps to connect to the server with JDBC. Tools In this demo, I am using SQL Workbench to connect to the server. SQL Server Express is 2017 version. JDBC is 7.1.x from Maven Repo. Steps …