Many of us have encountered a situation where you need to manage multiple Github accounts from a single computer – You may have two Github accounts, one related to work and the other for personal repositories.
To achieve this, all it takes is a very simple combination of ssh and git config. The below steps are meant for LINUX/UNIX users.
$ ssh-keygen -t rsa -b 4096 -C "work.emailid"Generating public/private rsa key pair.Enter file in which to save the key (/home/user/.ssh/id_rsa):Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /home/user/.ssh/id_rsa.Your public key has been saved in /home/user/.ssh/id_rsa.pub.
Create a second key for the personal Github account. Make sure that when you are prompted for the filename when generating the SSH keys for the second account, you give the appropriate filename.
$ssh-keygen -t rsa -b 4096 -C "personal.emailid"Generating public/private rsa key pair.Enter file in which to save the key (/home/user/.ssh/id_rsa): /home/user/.ssh/id_rsa_personalEnter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /home/user/.ssh/id_rsa_personal.Your public key has been saved in /home/user/.ssh/id_rsa_personal.pub.
ssh-config-file.sh
to the file on your system.# Default GitHubHost personal-github.comHostName github.comUser gitPreferredAuthentications publickeyIdentityFile ~/.ssh/id_rsa_personal# Work GitHubHost github.comHostName github.comUser gitPreferredAuthentications publickeyIdentityFile ~/.ssh/id_rsa
Once you save this file, you need to configure your git repos on local accordingly.
git@github.com
part in the remote origin of all your personal repositories to git@personal-github.com
–
and that’s it!From now on, the appropriate user account will be used when pushing to these repositories.
Free Resources