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.
| Account | Host | Alias |
|---|---|---|
| Office (Enterprise) | github.organisation.com | organisation |
| Personal | github.com | github-personal |
| Cloud / Work | github.com | github-cloud |
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_cloudSkip the passphrase or set one, macOS Keychain handles it either way.
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~/.ssh/configThis 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.
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_cloudThis persists the keys across reboots so you don't have to re-add them every session.
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.
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.gitFor repos you already have locally, update the remote:
git remote set-url origin git@github-personal:username/repo.git
# Verify
git remote -vGit 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"Edit ~/.gitconfig to conditionally include a profile based on where the repo lives:
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-organisation
[includeIf "gitdir:~/personal/"]
path = ~/.gitconfig-personalCreate ~/.gitconfig-organisation:
[user]
name = Username
email = you@organisation.comCreate ~/.gitconfig-personal:
[user]
name = Username
email = you@personal.comNow any repo inside ~/work/ automatically commits as your office identity. No per-repo config needed.
| Action | Command |
|---|---|
| Clone office repo | git clone git@organisation:org/repo.git |
| Clone personal repo | git clone git@github-personal:rinamasrina/repo.git |
| Clone cloud repo | git clone git@github-cloud:org/repo.git |
| Fix existing remote | git remote set-url origin git@<alias>:user/repo.git |
| Test SSH connection | ssh -T git@<alias> |
| Check active identity | git config user.email |