How to Access Both Company and Personal GitHub Repositories On The Same Machine

Published: (December 10, 2025 at 05:06 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Introduction

Managing multiple GitHub accounts—personal and company—can be tricky, especially when you need to keep repositories separate and avoid committing to the wrong account. Using distinct SSH keys for each account simplifies the workflow and improves security.

Step 1: Generate Two SSH Key Pairs

Create a dedicated RSA key pair for each GitHub account.

Company account

ssh-keygen -t rsa -b 4096 -C "your-company-email@example.com" -f ~/.ssh/id_rsa_company
  • -C adds a comment (usually your email) to identify the key.
  • -f specifies the filename so the default key isn’t overwritten.

You’ll be prompted to set a passphrase—highly recommended.

The command creates:

  • ~/.ssh/id_rsa_company (private key)
  • ~/.ssh/id_rsa_company.pub (public key)

Personal account

ssh-keygen -t rsa -b 4096 -C "your-personal-email@example.com" -f ~/.ssh/id_rsa_personal

This creates:

  • ~/.ssh/id_rsa_personal (private key)
  • ~/.ssh/id_rsa_personal.pub (public key)

Step 2: Configure SSH to Use the Right Key

Edit (or create) ~/.ssh/config and define host aliases for each account.

vi ~/.ssh/config

Add the following:

# Company GitHub Account
Host github-company
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_company
  IdentitiesOnly yes

# Personal GitHub Account
Host github-personal
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_personal
  IdentitiesOnly yes

Save and close the file. You can add more sections if you manage additional accounts.

Step 3: Add Public Keys to Your GitHub Accounts

Company account

cat ~/.ssh/id_rsa_company.pub

Copy the entire output (starting with ssh-rsa and ending with your email).

  1. Go to Settings → SSH and GPG keys in your company GitHub account.
  2. Click New SSH key, give it a title, paste the key, and save.

Personal account

cat ~/.ssh/id_rsa_personal.pub

Repeat the same steps in your personal GitHub account to add the key.

Cloning Repositories with the Correct Host

When cloning, use the host alias you defined in ~/.ssh/config.

Personal repository

git clone git@github-personal:USERNAME/REPO.git

Company repository

git clone git@github-company:USERNAME/REPO.git

Replace USERNAME/REPO with the appropriate repository path.

Setting a Remote for an Existing Local Repository

To push to the correct account, add a remote that uses the corresponding host alias.

Personal remote

git remote add origin git@github-personal:USERNAME/REPO.git

Company remote

git remote add origin git@github-company:USERNAME/REPO.git

Now git push and git pull will automatically use the right SSH key.

Quick Reference

AliasHost in ~/.ssh/configKey file
github-personalgithub.com~/.ssh/id_rsa_personal
github-companygithub.com~/.ssh/id_rsa_company

With these steps, you can seamlessly work with both personal and company GitHub repositories on the same machine.

Back to Blog

Related posts

Read more »