Managing Multiple Github Accounts on a Single Machine.

Kashish Bakshi
Arthashastra Intelligence
3 min readJul 21, 2020

Apart from helping and contributing to the Community and a lot more blah, this post has an ulterior motive, DOCUMENTATION!

Yes!

I Know. You heard it Right. I am just making my life easy somehow 😊

It's just that I used to end up surfing for the how to’s of something I have done over half a dozen times. Hence I thought of putting in a little bit of Effort and Voila! Here we are.

Prerequisites:

Public-Private Key Pairs and SSH(would really recommend watching this Playlist)

Let's Jump right on Point

Generating the SSH keys

First. Check to see whether you have an existing SSH Key.

cd ~/.ssh

ls

This will list out all existing public and private key pairs if any.

This is how my ssh Folder looks like

If ~/.ssh/id_rsa is available, we can reuse it, or else we can first generate a key using

ssh-keygen

When asked for the location to save the keys, accept the default location by pressing enter. A private key and public key ~/.ssh/id_rsa.pub will be created at the default ssh location ~/.ssh/.
As you can see that I already have one so I will skip this Step.

Now, I have two Github Accounts (Personal and Professional)

Lets first add this key to our Personal Account.

Copy the public key:

pbcopy < ~/.ssh/id_rsa.pub

Then log in to your personal GitHub account:

  1. Go to Settings
  2. Select SSH and GPG keys from the menu to the left.
  3. Click on New SSH key, provide a suitable title, and paste the key in the box below
  4. Click Add key — and you’re done!

For our Professional Account, we will create different SSH Keys.

The below code will generate the Key Pair for our Professional Account.

$ ssh-keygen -t rsa -C "kashish@aidatabases.in" -f "id_rsa_aidatabases"
This is how my Updated ssh Folder looks like

After creating those keys, Add the Keys in your Professional Github Account, following the same steps as before.

Registering the new SSH Keys with the ssh-agent

To use the keys, we have to register them with the ssh-agent on our machine

Add the keys to the ssh-agent:

ssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/id_rsa_aidatabases

Lets now make the SSH Agent use the respective SSH keys for the different SSH Hosts.

List all the SSH keys attached to the ssh-agent

ssh-add -l

If you are using your Personal Git Account

$ ssh-add -D            //removes all ssh entries from the ssh-agent
$ ssh-add ~/.ssh/id_rsa // Adds your Personal Key

If you want to switch to your Professional Git Account:

$ ssh-add -D
$ ssh-add ~/.ssh/id_rsa_aidatabases

This requires switching Manually in b/w different Git Accounts though.

We are done!

--

--

Kashish Bakshi
Arthashastra Intelligence

I am becoming what i never knew that i always wanted to be.