How setup multiple Github account ?

In this article we are going to discuss how to setup multiple github account in same device. We are going to do it through the ssh.

First thing we are going to do is create a ssh key for our personal account. To create the ssh key open the terminal and write below command and hit enter.

ssh-keygen -t rsa -C "your-email-address"

After running the above command you will able to see a file name id_rsa and id_rsa.pub in you .ssh directory to navigate to .ssh directory follow the below command in mac os.

cd ~/.ssh

Now we will create another ssh key with our company's email address using below command.

ssh-keygen -t rsa -C "your-email-address"

When it asks for the file name of ssh enter something like this id_rsa_COMPANY_NAME this will create two more file called id_rsa_COMPANY_NAME and id_rsa_COMPANY_NAME.pub.

Now we will create a file called config in .ssh directory using this command.

touch ~/.ssh/config

We will edit our config file something like this.


#Default GitHub
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa

Host github-COMPANY_NAME
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_COMPANY_NAME

Now we need to open our id_rsa.pub and copy the content of the file and place it in you personal github account.

First go login to github account and navigate to settings then at the left sidebar you will able to see ssh gpg key click on this and add your ssh public key here.

After doing this similarly we need to put our id_rsa_COMPANY_NAME.pub content to our company's github account.

After all this we are good to go.

Now while cloning the repo just make sure to clone repo from the your company's account your url should look something like this git@github-COMPANY_NAME:COMPANY_USERNAME/gradient-generator.git as we have defined in HOST in our config file above.

Did you find this article valuable?

Support adityakmr by becoming a sponsor. Any amount is appreciated!