
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.
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
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 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.
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_orgNow, instead of github.com, you’ll reference github.com-personal or github.com-org.
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 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.
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.
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.
0
9
2