10 December 2022 by William Estoque
Using Git with Multiple GitHub Accounts
Using git with multiple GitHub accounts present many problems for the user because one simply cannot use the same SSH public key for different accounts.
You can use HTTP but then you have to input your GitHub username and password everytime you have to push/pull.
We have created the guide below so you can use GitHub using multiple accounts with the easiest setup.
The steps to use GitHub using multiple accounts:
-
Create your new GitHub user
Here at Narra Labs, we follow a naming pattern for naming a new GitHub user. If your personal GitHub username for example is
westoque
, and you are working for a company namednarralabs
, then your new company GitHub account username would bewestoque-narralabs
. -
Generate a new ssh key pair for your new user using
ssh-keygen
and follow the instructions. Make sure to name the SSH key using the same pattern as your newly created GitHub username.westoque@milan$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/westoque/.ssh/id_rsa): westoque-narralabs
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in westoque-narralabs
Your public key has been saved in westoque-narralabs.pub
The key fingerprint is:
SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX westoque@milan.lan
The key's randomart image is:
+---[RSA 3072]----+
| X XXXXXX |
| X X XXXX |
| X XXXX |
| X X XX |
| X XXX |
| X X X |
| X |
| |
| |
+----[SHA256]-----+Two files will be generated by the command above:
-
The private key:
westoque-narralabs
-
The public key:
westoque-narralabs.pub
-
The private key:
-
Move the new SSH key files to your
~/.ssh
directorymv westoque-narralabs westoque-narralabs.pub ~/.ssh
-
Modify your SSH config by modifying ~/.ssh/config:
Add the line below to tell the SSH program that you have a new host using the following configurations.
Host github-westoque-narralabs
	User git
	HostName github.com
	IdentityFile ~/.ssh/id_rsa_westoque_narralabs -
Clone the project using your new host:
The original GitHub SSH clone link would look like below:
git@github.com:narralabs/brackets.git
You then have to modify it using your new host:
github-westoque-narralabs:narralabs/brackets.git
Then clone the project:
git clone github-westoque-narralabs:brackets.git
- You can now push/pull like normal for this specific repository.
You can repeat the steps above for another GitHub account.