Using multiple GitHub account for git operation

Jurin Liyun
2 min readFeb 17, 2023

For those who has multiple account on GitHub namely, for personal and for work, this tutorial might be useful for you. Due to the deprecation of password authentication in GitHub for git operations, they suggest that developer should use SSH Key to authenticate.

In this simple tutorial, I will guide you step by step and hope that you can setup your own later on.

  1. Generate SSH Key.
$ ssh-keygen -t ed25519 -C "You email address"
$ cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKTG6CJe6XtJxDWXnSgmFS0cp8oNY/ email@example.com

2. Copy the public key to github profile. Go to profile->settings, click on the SSH and GPG keys link.

SSH and GPG Keys
Click Add SSH Key after all the required completed

3. Create configfile in ~/.ssh/ directory

Create config file in .ssh directory

After config has successfully created, then copy and paste the code below into your config.

Host me.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

Host work.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_ed25519

Then run the ssh test to make sure all configuration working well.

Successful ssh test

4. Set your origin url to git@github.com/<owner>/project.git

After going through all the steps above, you can test to pull the latest changes in for your repository by running git pull origin master or upstream. I hope that this tutorial could help some of you who in search for an answer that dealing with multiple GitHub account in one workspace.

Thanks for reading.

--

--

Jurin Liyun

Developer, Trainer , Consultant, Father of two children