How to use multiple GitHub accounts on the same PC
- Tram Ho
Today we will learn how to use many github accounts on the same computer!
Step 1: Create a new ssh key for the work account
1 | ssh-keygen -t rsa -C "github-email-address" |
When the screen shows Enter file in which to save the key (/home/<user>/.ssh/id_rsa):
user> Enter file in which to save the key (/home/<user>/.ssh/id_rsa):
Enter the user for your job, for example I will enter id_rsa_sun
Check if id_rsa_sun was born.
1 | cd cd ~ / .ssh |
1 | ls |
List of generated files:
1 | id_rsa_sun id_rsa_sun.pub id_rsa id_rsa.pub |
Step 2: Install ssh key on github
Get the id_rsa of the new email you just created.
1 | cat id_rsa_sun.pub |
Then enter the ssh-key of your git account at https://github.com/settings/keys
Step 3: Install Github Host
1 | touch ~ / .ssh / config |
1 | nano ~ / .ssh / config |
Edit your config file to:
1 2 3 4 5 6 7 8 9 10 | # Your personal git account is still in use Host github.com-username Github.com HostName User git IdentityFile ~ / .ssh / id_rsa # Work account This github.com-sun # config host will be used to handle the determination when configuring the remote Github.com HostName User git IdentityFile ~ / .ssh / id_rsa_sun # id_rsa_sun that we just created |
After creating a project on github with another account. When you add remote
, pay attention to user when adding. For example when clone a new repo:
1 | git clone git@github.com-sun: <user> /sample_ruby.git |
1 | git config user.email "<emai use to generate id_rsa_sun above>" |
You can then add and commit normally.
Add remote with new repo:
1 | git remote add origin git@github.com-sun: <user> /sample_ruby.git |
Note: sun
here is my user set, you can change according to the work user or nick name you want accordingly.
Source: Git Push & Pull with Two accounts and Two users on the same machine
Source : viblo.asia