← LOGBOOK LOG-326
COMPLETE · SOFTWARE ·
GITGITHUBSSHDEVTOOLSWORKFLOW

Multiple GitHub Accounts on One Machine via SSH Config

Using SSH host aliases to manage two separate GitHub accounts from the same machine — no credential conflicts, no manual identity switching.

The Problem

Two GitHub accounts. One machine. Git can only use one set of credentials at a time unless you tell it otherwise.

The naive fix — logging in and out, copying keys around — falls apart immediately in practice. You need both accounts usable simultaneously, with no manual switching.

How SSH Host Aliases Work

SSH’s ~/.ssh/config file lets you define named host aliases. Each alias can map to the same real hostname but use a different identity file. Git uses the SSH URL you give it, so if you craft URLs that use different alias names, SSH picks the right key automatically.

GitHub doesn’t care what hostname you use in the SSH config — it only looks at which key you authenticated with to determine which account you’re connecting as.

The Config

Host account-a
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_account_a
  IdentitiesOnly yes

Host account-b
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_account_b
  IdentitiesOnly yes

IdentitiesOnly yes is important — without it, SSH may try other loaded identities (e.g. from the agent) and pick the wrong one.

Cloning with the Right Identity

Instead of the standard git@github.com:user/repo.git, substitute the alias:

# Account A
git clone git@account-a:username-a/repo.git

# Account B
git clone git@account-b:username-b/repo.git

Repos cloned this way have the alias baked into their remote URL. Every subsequent git push and git pull automatically uses the correct key.

Checking an Existing Remote

For repos already cloned, check the current remote:

git remote -v

If it shows git@github.com:... instead of the alias, update it:

git remote set-url origin git@account-a:username-a/repo.git

Verifying the Connection

Test each alias independently:

ssh -T git@account-a
# Hi username-a! You've successfully authenticated...

ssh -T git@account-b
# Hi username-b! You've successfully authenticated...

If you get Permission denied (publickey), the key isn’t added to that GitHub account, or the IdentityFile path is wrong.

Per-repo Git Identity

SSH handles which account authenticates. Separately, you may want each repo to commit under a different name/email. Set these locally per repo:

git config user.name "Name A"
git config user.email "email-a@example.com"

Without --global, this only applies to the current repo. The global config stays as your default.

What Stuck

The alias name is just a label — it can be anything, as long as the SSH config and the clone URL agree on what it is. The entire mechanism is just SSH routing different aliases to the same github.com server with different keys. No third-party tools, no credential managers, no environment variables needed.