Photo by Yancy Min on Unsplash

Working with several git accounts

📅September 06, 2019

I have two git account, personal account, and company account. I’m working on one machine with several projects. Now I want to switch between the personal account and company account to do something like pushing on my personal GitHub repo. Or basically working on two account and easy to switch them every time. Here are the steps to do that:

Create new SSH key

For MacOS I used

ssh-keygen -t rsa -C "your-email-address"
  • -t stands for ‘type’ and rsa is type of encryption
  • -C is for comment

After enter, the result will be showing

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/

By default, if we don’t type anything and hit enter, it will auto-create an file. And if we want to add more one account, we have to create another idrsa file. For example, create idrsacompany file:


Note: Make sure you don’t override id_rsa as this is your existing key for your original account.

Next, enter a passphrase or leave it blank, then hit enter, the output will show:

Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/
Your public key has been saved in /Users/
The key fingerprint is:
The key's randomart image is:
+---[RSA 2048]----+
|   .+=...        |
| .o.==o  +       |
|.o.=..* o o      |
|. oo*+ = o       |
| .oooo. S        |
|.=    =..        |
|=.o. o * .       |
|.+. = . E        |
|...oo+           |

After that, new file will be created in our machine, let’s check by typing this command:

ls -la ~/.ssh

By doing that, all of the SSH keys have been shown:

drwx------  10  1893963146   320 Sep  6 09:20 .
drwxr-xr-x+ 43  1893963146  1376 Sep  6 09:25 ..
-rw-r--r--   1  1893963146   187 Sep  5 16:06 config
-rw-------   1  1893963146  1896 Aug  9 13:05 id_rsa
-rw-r--r--   1  1893963146   418 Aug  9 13:05
-rw-------   1  1893963146  1876 Sep  6 09:20 id_rsa_company
-rw-r--r--   1  1893963146   402 Sep  6 09:20
-rw-------   1  1893963146  1896 Sep  5 15:57 id_rsa_personal
-rw-r--r--   1  1893963146   411 Sep  5 15:57
-rw-r--r--   1  1893963146  1198 Sep  5 16:11 known_hosts

And we should be able to see our new SSH key. Both idrsacompany and

  • idrsacompany is our private key stored on our machine.
  • is the public key which we will provide GitHub with.

Add SSH and GPG keys on Github

Open file and copy all content.

vim ~/.ssh/

And copy all of this

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCkCbwThaCvimqncTrhWej95JMhXcohhEXEbuaXfK3oNS86SC4KnrPp92x4+BaPirDnC8qYVsGJ+rdBajnudn18LFjzqqHtRZcLzZRBwO6jyFs9R0nXOYPMqnWhaxUG874Rqh2AMhFPinDpqgY/pj5s7gkqFDGnr3lojVzvlnrBkEC69bZ0QVl7rBP+OONvAKhnJbRK1A/xUYVZfLAOPMQ9RbN5zKt8+gtYhb7M37y2m5OAaGguYvOxnIk9ZXOh1YsudKPElI7cYY/9Y9JgvVOtxNt50wkfeXxb8knEecNU7VJKq2S04mxj3OiD0QwPVsT63ToDUmV/gGKglYKN6srJ

Or simple type:

pbcopy < ~/.ssh/

Access on Github and navigate to your Github account => Settings => SSH and GPG keys


Click New SSH key


Give it a title and paste new generated SSH key that you’ve copied before.

Because we saved our key with a unique name, we need to tell SSH about it. Within the Terminal

In MacOS, type:

ssh-add ~/.ssh/id_rsa_company

If successful, you’ll see a response of “Identity Added.”

For Windows, type:

git config core.sshCommand=ssh -i ~/.ssh/id_rsa_company

Pushed to GitHub with the associated account

First, check current logged account in your machine by typing this command to show the email:

git config

Or this command to show all of the infomation about logged account:

git config --list

Make sure that you’re right account, or switch to another account if needed, for example:

git config "phuongthuan"
git config ""

Commit and Push to your repositories

git init
git add .
git commit -m "First commit"
git remote add origin
git push origin master

Hey. I'm Thuan.
I write anything to help others.