Currently, I am working for a company where they create a Github account using the company’s email id and all the repository access would be given to that Github account.
But I have a personal Github account as well and I am quite active in that too.
Now the problem is, How to manage the SSH keys for both the GitHub accounts. Git by default takes the ~/.ssh/id_rsa(.pub) keys and we can’t add the same ssh key in both the GitHub account.
We can manage multiple Github accounts using the ssh config file.
Create a new ssh key pair
Generate a new ssh key pair using the company’s email id.
ssh-keygen -t rsa -b 4096 -C "email@example.com"
In the prompt, specify a different file name.
Add the ssh key to the ssh-agent
Now add the generated key using the ssh-add command.
Identity added: /Users/prasanna/.ssh/id_rsa_my_company (firstname.lastname@example.org)
Add the id_rsa_my_company.pub key to your company Github account.
Update the hosts in the ssh config file
Update the config file (~/.ssh/config) with these values and it should have entry to for you personal Github account,
My Company Github Account
Personal Github Account
Clone your personal Github and company Github projects
You can clone your personal private projects using the command,
git clone email@example.com:your-github-account/private-repo.git
You can clone your company ‘s private projects using the command,
git clone firstname.lastname@example.org:company-acc/private.git
That’s it. Hope it will be useful. Let me know If you have any questions in the comment section.
Top comments (1)
Thank you so much, this is so helpful.