Table of Content
Currently, we have multiple accounts on the same host - https://github.com/. It’s difficult to work on lots of projects at the same time. Because it can cause the issue of using the personal mail for our work projects. It will violate the security of our companies.
How do we solve this issue?
Some steps to use multiple Github accounts on the same machine
Create a new SSH key for each account on terminal
On Git Bash terminal, typing the following command:
ssh-keygen -t rsa -C "your_mail_address"
-tstands for “type” and
rsais type of encryption.
-Cstands for “comment”.
Then, it will show like the below comment:
Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/your_username/.ssh/id_rsa):
We can type the name for this key as “id_rsa_
Then, we’re defining the
We can find these files in
In this step, we don’t need to fill some words for passphrase.
Check these key files in
ls -al ~/.ssh
Then, we have:
The content of this config file will follow the below rules:
# Personal github Host personal HostName github.com User git IdentityFile ~/.ssh/id_rsa_personal_github # Work github Host name_company HostName github.com User git IdentityFile ~/.ssh/id_rsa_name_company_github
Add public key file’s content to Github.
Navigate to your
Github account --> Settings --> SSH and GPG Keys.
In this step, click
New SSH keybutton to create a new ssh public key on Github.
Then, we copy the public key file’s content to Github.
After that, it will look like the above image.
Test your connection with Github.
ssh -T git@personal ssh -T git@name_company
Then, we can have:
Setup configuration for our projects.
If our project’s Git is existing with HTTPS mode, we should change it to using SSH mode.
# configure our name and email git config user.name "our-name" git config user.email "our-email" # configure Git's url git remote set-url origin git@`Host`:someone/name-project.git
For example, below is the configuration file in
Actually, we don’t need to configure
sshCommandfield to the command of ssh.
If we didn’t clone a project some time, we will follow the below commands:
# Personal Project $ git clone git@personal:someone/project.git $ cd /path/to/project $ git config user.email "email@example.com" $ git config user.name "name" # Work Project $ git clone git@name_company:someone/project.git $ cd /path/to/project $ git config user.email "firstname.lastname@example.org" $ git config user.name "work name"
If we want to push a new projects to Github.
git init git add . git commit -m "First commit" git remote add origin git@personal:someone/project.git git push origin master
To check our steps above is successful or not.
Run the below command.
Then, we have:
That’s it for the guide that configures multiple Github accounts on one machine.
Thanks for reading. Have a great day.