Skip to content

Instantly share code, notes, and snippets.

@brayevalerien
Created March 8, 2026 04:14
Show Gist options
  • Select an option

  • Save brayevalerien/c2efe8ec094d30e5a4f0b2cf4e8f2047 to your computer and use it in GitHub Desktop.

Select an option

Save brayevalerien/c2efe8ec094d30e5a4f0b2cf4e8f2047 to your computer and use it in GitHub Desktop.
Quick guide on how to setup and use two Github SSH identities on the same machine, for instance work and personal.

Setting up dual GitHub SSH identities on one machine

1. Generate two SSH keys

ssh-keygen -t ed25519 -C "personal@email.com" -f ~/.ssh/id_ed25519_personal
ssh-keygen -t ed25519 -C "work@email.com" -f ~/.ssh/id_ed25519_work

2. Add each public key to its GitHub account

Copy each .pub file content and add it under Settings > SSH and GPG keys on the corresponding GitHub account.

cat ~/.ssh/id_ed25519_personal.pub
cat ~/.ssh/id_ed25519_work.pub

3. Configure SSH host aliases

In ~/.ssh/config, create a distinct host alias per account:

Host gh-personal
   HostName github.com
   User git
   AddKeysToAgent yes
   IdentitiesOnly yes
   IdentityFile ~/.ssh/id_ed25519_personal

Host gh-work
   HostName github.com
   User git
   AddKeysToAgent yes
   IdentitiesOnly yes
   IdentityFile ~/.ssh/id_ed25519_work

IdentitiesOnly yes is critical. Without it, the SSH agent may offer the wrong key first, causing authentication to succeed as the wrong user.

4. Add keys to the agent

ssh-add ~/.ssh/id_ed25519_personal
ssh-add ~/.ssh/id_ed25519_work

5. Test

ssh -T gh-personal   # should print: Hi <personal-username>!
ssh -T gh-work       # should print: Hi <work-username>!

6. Clone using the host alias

Instead of the standard github.com hostname, use your alias:

git clone git@gh-personal:personal-user/repo.git
git clone git@gh-work:work-org/repo.git

For existing repos, update the remote:

git remote set-url origin git@gh-personal:personal-user/repo.git

7. Per-repo git identity (optional)

Git author info is separate from SSH. Set it per repo to avoid committing under the wrong name:

cd ~/work-repo
git config user.name "Work Name"
git config user.email "work@email.com"

Or use conditional includes in ~/.gitconfig to automate by directory:

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

Where ~/.gitconfig-work contains:

[user]
    name = Work Name
    email = work@email.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment