← Back to Blog

Setup Multiple GitHub Accounts on Mac

2026-05-02·3 min read
GitHubSSHGitmacOSDeveloper Setup

If you work across multiple GitHub accounts, you've probably hit the authentication wall. Git doesn't know which account to use, and credentials get crossed.

The fix is SSH with a per-host config. Here's the full setup.


What we're working with

AccountHostAlias
Office (Enterprise)github.organisation.comorganisation
Personalgithub.comgithub-personal
Cloud / Workgithub.comgithub-cloud

1. Generate SSH keys

One key per account. Keep them clearly named.

# Office — GitHub Enterprise
ssh-keygen -t ed25519 -C "you@organisation.com" -f ~/.ssh/id_organisation
 
# Personal
ssh-keygen -t ed25519 -C "you@personal.com" -f ~/.ssh/id_github_personal
 
# Cloud / work
ssh-keygen -t ed25519 -C "you@work.com" -f ~/.ssh/id_github_cloud

Skip the passphrase or set one, macOS Keychain handles it either way.


2. Add public keys to GitHub

Copy each public key and paste it into the respective account's SSH settings.

cat ~/.ssh/id_organisation.pub     # → github.organisation.com → Settings → SSH Keys
cat ~/.ssh/id_github_personal.pub  # → github.com (personal) → Settings → SSH Keys
cat ~/.ssh/id_github_cloud.pub     # → github.com (cloud) → Settings → SSH Keys

3. Configure ~/.ssh/config

This is the core of the setup. Each Host block maps a custom alias to the real hostname and the right key.

# Office — GitHub Enterprise
Host organisation
  HostName github.organisation.com
  User git
  IdentityFile ~/.ssh/id_organisation
  IdentitiesOnly yes

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

# Cloud / work GitHub
Host github-cloud
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_github_cloud
  IdentitiesOnly yes

IdentitiesOnly yes is important: it prevents SSH from trying other loaded keys before the one you specified.


4. Register keys with macOS Keychain

ssh-add --apple-use-keychain ~/.ssh/id_organisation
ssh-add --apple-use-keychain ~/.ssh/id_github_personal
ssh-add --apple-use-keychain ~/.ssh/id_github_cloud

This persists the keys across reboots so you don't have to re-add them every session.


5. Test each connection

ssh -T git@organisation     # Hi <you>! You've successfully authenticated...
ssh -T git@github-personal  # Hi rinamasrina! You've successfully authenticated...
ssh -T git@github-cloud     # Hi <clouduser>! You've successfully authenticated...

If you see Permission denied (publickey), double-check that the public key was added to the right GitHub account and that the IdentityFile path is correct.


6. Use the alias when cloning

Replace github.com or github.organisation.com with your alias when cloning.

# Office
git clone git@organisation:org/repo.git
 
# Personal
git clone git@github-personal:rinamasrina/repo.git
 
# Cloud / work
git clone git@github-cloud:org/repo.git

For repos you already have locally, update the remote:

git remote set-url origin git@github-personal:username/repo.git
 
# Verify
git remote -v

7. Set commit identity per repo

Git will use your global user.name and user.email by default. Override it per repo so commits land under the right account.

cd ~/path/to/repo
git config user.name "Username"
git config user.email "you@personal.com"

Better: auto-apply identity by directory

Edit ~/.gitconfig to conditionally include a profile based on where the repo lives:

[includeIf "gitdir:~/work/"]
  path = ~/.gitconfig-organisation
 
[includeIf "gitdir:~/personal/"]
  path = ~/.gitconfig-personal

Create ~/.gitconfig-organisation:

[user]
  name = Username
  email = you@organisation.com

Create ~/.gitconfig-personal:

[user]
  name = Username
  email = you@personal.com

Now any repo inside ~/work/ automatically commits as your office identity. No per-repo config needed.


Quick reference

ActionCommand
Clone office repogit clone git@organisation:org/repo.git
Clone personal repogit clone git@github-personal:rinamasrina/repo.git
Clone cloud repogit clone git@github-cloud:org/repo.git
Fix existing remotegit remote set-url origin git@<alias>:user/repo.git
Test SSH connectionssh -T git@<alias>
Check active identitygit config user.email