How to use multiple GitHub accounts on one machine

23rd July 2022

I needed to create a new GitHub account for work, but I didn't want to switch my credentials every time I pushed, cloned, or pulled from my private repositories.

I quickly googled how to achieve this without much hassle, and here it is:

1. Generate the SSH keys for both your work and private emails.

It will ask you to enter a unique file name and passphrase. I liked the file name pattern from the other blog post, so I borrowed (stole) it - id_rsa_personal and id_rsa_work
Don't forget to save the passphrase somewhere safe! For example in 1password.

$ cd .ssh/
$ ssh-keygen -t rsa -C ""
$ ssh-keygen -t rsa -C ""

I am not sure if you should keep the commands' output, but I did! Just in case!

2. Copy the SSH keys and paste them into the appropriate GitHub account

$ ls
$ cat | pbcopy
$ cat | pbcopy

Log in to the appropriate GitHub account, go to settings. Click on the SSH and GPG keys, and paste one of the ssh keys.

3. Setup SSH config

You need to create an SSH config with both hosts configured.

$ vim ~/.ssh/config
# replace IdentityFile with your own file name and :wq
User git
IdentityFile ~/.ssh/id_rsa_personal
User git
IdentityFile ~/.ssh/id_rsa_work

4. Add the SSH keys to the SSH Agent

$ ssh-add ~/.ssh/id_rsa_personal
$ ssh-add ~/.ssh/id_rsa_work

5. Clone the repository to test things out

$ git clone


Bart Stefański

A self-taught full-stack software engineer based in Poland, working in React.js & Nest.js Stack. Passionate about Clean Code, Object-Oriented Architecture and fast web.