How to use multiple GitHub accounts in a system(Linux or Mac)

JS Developers
3 min readApr 30, 2020

--

Photo by Caleb White on Unsplash

Hi Geeks, Here I’m writing about how to work on multiple GitHub accounts in a single system. when I need this faced some issue and not find a simple solution so I’m writing this in a very simple step

Step 1

Open terminal (Ctrl+Alt+t) and type

ssh-keygen -t rsa -C “your-email-address”

here -t stands for Type, RSA is encryption type and -C is for comment

then it will for path to save it

Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):

change the path /home/user/.ssh/id_rsaSAMPLE(don’t press Enter without path otherwise it will overwrite the already existing key)

and then it will ask for a passphrase just enter two times and it will return key fingerprint.

now in terminal go into .ssh(cd .ssh
) directory. there will be two files with the name you created

  1. id_rsaSAMPLE- Contains private key stored on your machine
  2. id_rsaSAMPLE.pub - Contains public key which needs to add on Github

type vim id_rsaSAMPLE.pub or open with whatever editor you used and you can see your ssh-rsa key

the key will be something like

ssh-rsa AAAAbbbbbbcccccQ87YYHHFFF/VfACbzbYn0d5TQRQe9IdPvbV+tm9wSD8/sWlkghtjdheuebrn67d83nbd8e4nufn4i4nrfjfirnfi4459440URj “your email-address”

Copy this key and paste in the field mentioned in second step

Step 2

open your Github account and open SettingsSSH and GPG keys

click on New SSH key

Add ssh key

Add some title and paste the key in the key section have copied from the terminal and click on Add SSH key button

Step 3

open the terminal and again go to .ssh directory and edit config file like below and save it.

#default official account
Host github.com
HostName github.com
User git
identityFile ~/.ssh/id_rsaSample
#default personal account
Host sample
HostName github.com
User git
identityFile ~/.ssh/id_rsa

Here the Host will be different for each account and identityFile will be the address of the public key file.
Now you are almost there to use different accounts in the same terminal.

just use git with the different host for different account

git@<host-in-ssh-config>:<username>/<repo>

for example -

git clone git@sample:sachin9663/sample for official account
git clone git@github.com:sachin9663/sample for personal account

--

--

JS Developers
JS Developers

Responses (1)