Managing Multiple Github Accounts on a Single Machine
A Step-by-Step Guide to Setting Up and Using SSH Keys

Fullstack Developer | CSS | JavaScript | React | Angular | Web3
Prerequisite:
You should have a GitHub account.
You should have a basic knowledge of how to create repositories, what is git and GitHub and how to use them?
This article is for someone who wants to add their personal, and professional github accounts on the same machine.
To set up multiple GitHub accounts on a single machine, you need to use SSH keys. SSH keys are used to authenticate the connection between your computer and GitHub and secure the data transmission.
Follow these steps to set up multiple GitHub accounts on a single machine:
- Create a folder named
.sshin your home directory using the following command:
cd ~
mkdir .ssh
Generate SSH keys for each of the two accounts using the following commands:
ssh-keygen -t rsa -P "" -f person1 ssh-keygen -t rsa -P "" -f person2It will create the following files inside
.sshfolderperson1 person1.pub person2 person2.pubthe
.pubmeans ->public_keythat is used for authenticationYou can see the content of
.pubfiles usingcatcommand or you can open it innotepad.Add the public keys to their respective GitHub accounts by copying the contents of the public key files and adding them as new SSH keys in GitHub. To do this:
Go to your GitHub account.
Open settings.
Inside SSH and GPG keys, click on the New SSH key.
Copy the data from
person1.puborperson2.pub(depending on the account) from your computer and paste it into the key section in GitHub.Set the title as
person1orperson2(depending on the account).Click Add SSH Key.
Create a config file in the
.sshfolder using the following command:touch configEdit the config file to specify the location of the private keys for each of the accounts: ( Just paste the following text and change
person1andperson2as yours that you used while creating )Host person1 HostName github.com User git IdentityFile ~/.ssh/person1 Host person2 HostName github.com User git IdentityFile ~/.ssh/person2To clone a repository, use the following commands:
# cloning as person1: git clone person1:<github-username-1>/repo1.git # cloning as person2: git clone person2:<github-username-2>/repo2.gitTo set the correct authority for each repository, set the user name and email address for each repository separately using the following commands:
# For Person1: git config user.name person1 git config user.email email_id_of_person1 # For Person2: git config user.name person2 git config user.email email_id_of_person2
By following these steps, you should be able to successfully set up multiple GitHub accounts on a single machine.
Sometimes there occurs a problem in setting remote origin:
Using the following command might solve the problem:
If a GitHub repository looks like this:-
https://github.com/username/reponame.gitthen for adding it as a remote origin, the following command can be used :# for person1: git remote add origin person1:username/reponame.git # for person2: git remote add origin person2:username/reponame.git
That's all about it.
Hope you find the blog useful. If yes, then do upvote it.
Thank you for reading!!




