Managing multiple Github Accounts

Grace Yuiko Nakano
3 min readJul 26, 2021

Setting up and authenticating your personal and work accounts

I just completed my first week on the internship post bootcamp. It was a great week and I learned so much but also went through some growing pains, managing and linking my personal and work GitHub account through VS Code.

Oh no, why is my work not being pushed up to my GitHub!?
  1. Create ssh file locally
  • Before creating a new file, make sure you are in the appropriate directory. I created my ssh file under Users/gracenakano and then cd (stands for change directory) into the newly created file.
Users/gracenakano touch .ssh
Users/gracenakano cd .ssh

2. Generate SSH key for each of your accounts

  • Enter your personal email address associated with the account
Users/gracenakano cd .ssh
.ssh ssh-keygen -t rsa -b 4096 -C "personal_email@gmail.com"

This generates a public/private rsa key pair. The terminal will query the user to enter the file to save the key. Enter:

.ssh id_rsa_personal

I bypassed the passphrase questions so I wouldn’t need to type a password for each time I accessed this account, pressing enter until it brought me back to the .ssh directory.

  • Go through the same process to generate a rsa key pair for your work account, entering the work email associated to your work GitHub account.
.ssh ssh-keygen -t rsa -b 4096 -C "work_email@gmail.com"
.ssh id_rsa_work
.ssh ls
id_rsa_personal id_rsa_personal.pub id_rsa_work id_rsa_work.pub

3. Copy SSH key to paste in each GitHub account

.ssh cat id_rsa_personal.pub
  • Take the return SSH key value and copy and paste into your GitHub account.
  • In your GitHub account, go to Settings => SSH and GPG keys => New SSH Key.
  • Add title to key. You can call it anything such as “Grace’s MacBook”. Paste the SSH key to the body. Click Add SSH key
  • Repeat the process for your work account. Make sure to log out of your personal Github account and sign into your work account before continuing the process.
.ssh cat id_rsa_work.pub
  • You can title the key the same in your work account. Just make sure to copy and paste the correct SSH key.

4. Create config file under .ssh and add configurations

.ssh touch config
.ssh nano config
# Personal account - default config
Host github.com-gracenak
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
# Work account
Host github.com-gracenakano
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work

5. Create .gitconfig file for both accounts

  • Let’s start with the personal account:
.ssh cd
~ nano ~/.gitconfig
  • Add to the file:
[user]     
name = Grace Nakano
email = personal_email@gmail.com
[includeIf "gitdir:~/work/"]
path = ~/work/.gitconfig

Let’s go through the same process for the work account, but in addition, create a work directory.

~ mkdir work
~ nano ~/work/.gitconfig
  • Add to file:
[user]     
name = gracenakano
email = work_email@gmail.com

6. Add SSH keys

~ cd .ssh/
.ssh ssh-add id_rsa_personal
.ssh ssh-add id_rsa_work
# to see our list of keys .ssh ssh-add -l

7. Check configuration with the following commands

# personal
.ssh ssh -T github.com-gracenak
// prompt to continue => yesHi gracenak! You've successfully authenticated, but GitHub does not provide shell access# work
.ssh ssh -T github.com-gracenakano
// prompt to continue => yesHi gracenakano! You've successfully authenticated, but GitHub does not provide shell access

8. Clone down repo via SSH and add hostname in URL

  • add hostname in the following (indicated in bold below)
~ cd work/
work git clone git@github.com-gracenakano:gracenakano/test.git
  • we can check to see if we have cloned down and connected to the correct GitHub account
work cd test/
work/test git config user.email
work_email@gmail.com
  • follow the same procedure for your personal account by cloning down a personal repository via SSH and add host name as sampled above.

9. Test it out

  • create branch and add file
work/test git checkout -b test
work/test touch test.rb
work/test
git add .
work/test git commit -m"add test file"
work/test git log
Author: gracenakano <work_email@gmail.com>
work/test git push origin test
# pushes branch remotely
  • if we check our GitHub account, we should be able to see the new branch pushed up and merge it to our repository.

With this 9 step configuration, I am able manage my personal and work projects without any issues.

--

--

Grace Yuiko Nakano

Fullstack Software Engineer | Musician | Food Lover | Coffee Addict