Saurabh Sharma

Oct 01, 2025 • 2 min read

Managing and Using Multiple GitHub Accounts with SSH on One Machine

Managing and Using Multiple GitHub Accounts with SSH on One Machine

When working as both an individual developer and part of an organization, you may need to manage multiple GitHub accounts on the same machine. For example:

  • A personal GitHub account for open-source contributions and side projects.

  • An organization-provided GitHub account for professional or work-related repositories.

This guide walks you through configuring and using multiple GitHub accounts on the same system with SSH.


Step 1: Generate SSH Keys for Each Account

Create unique SSH keys for each GitHub account.

Personal account

ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_personal 

Organization account

ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_org 

This creates two key pairs:

  • ~/.ssh/id_rsa_personal and ~/.ssh/id_rsa_personal.pub

  • ~/.ssh/id_rsa_org and ~/.ssh/id_rsa_org.pub


Step 2: Add SSH Keys to the SSH Agent

Start the SSH agent and add the new keys:

eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa_personal ssh-add ~/.ssh/id_rsa_org 

Step 3: Add Public Keys to GitHub

Copy each public key and add it to the respective GitHub account.

cat ~/.ssh/id_rsa_personal.pub cat ~/.ssh/id_rsa_org.pub 

Then, go to GitHub → Settings → SSH and GPG keys → New SSH key, and add them.


Step 4: Configure the SSH Config File

Edit the SSH configuration file:

nano ~/.ssh/config 

nano ~/.ssh/config

Add the following entries:

# Personal account
Host github.com-personal
 HostName github.com
 User git
 IdentityFile ~/.ssh/id_rsa_personal

# Organization account
Host github.com-org
 HostName github.com
 User git
 IdentityFile ~/.ssh/id_rsa_org

Now, instead of github.com, you’ll reference github.com-personal or github.com-org.


Step 5: Clone Repositories with the Correct Account

Use the proper alias when cloning repositories.

Personal account

git clone [email protected]:username/repo.git 

Organization account

git clone [email protected]:orgname/repo.git 

Step 6: Set Up Global and Local Git Configs

Set a global config for your personal account:

git config --global user.name "Your Personal Name" git config --global user.email "[email protected]" 

Then, for organization projects, set a local config inside each repo:

cd repo git config user.name "Your Org Name" git config user.email "[email protected]" 

This ensures commits are attributed to the correct account.


Step 7: Verify the Setup

Check which identity is being used by testing each alias:

ssh -T [email protected] ssh -T [email protected] 

You should see confirmation messages from GitHub for each account.


Final Notes

  • You can manage any number of accounts by repeating this process.

  • Always use the correct SSH alias when cloning repositories.

  • Use local Git configs to avoid mixing up commit authorship.

With this setup, you can now seamlessly use multiple GitHub accounts on a single machine without conflicts.

Join Saurabh on Peerlist!

Join amazing folks like Saurabh and thousands of other builders on Peerlist.

peerlist.io/

It’s available... this username is available! 😃

Claim your username before it's too late!

This username is already taken, you’re a little late.😐

0

9

2