Multiple GitHub Accounts with SSH

Configure SSH to work with multiple GitHub accounts (personal and work) using separate keys and Host aliases. Essential for developers with dual accounts.

Authentication

Detailed Explanation

Managing Multiple GitHub Accounts via SSH

Many developers maintain separate GitHub accounts for personal and work projects. Since GitHub identifies you by your SSH key (not your username), you need distinct keys and Host aliases to switch between accounts.

Example Config

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

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

How It Works

Both Host entries point to github.com as the HostName, but each uses a different SSH key. The IdentitiesOnly yes directive is critical here: without it, SSH might offer all keys in your agent, and GitHub would authenticate you with the first key it recognizes, which may be the wrong account.

Updating Git Remotes

Instead of the standard remote URL:

git@github.com:myorg/project.git

Use the Host alias in your remote:

git@github-work:myorg/project.git

Per-Repository Git Config

Also set the correct Git identity per repository:

cd ~/work/project
git config user.email "work@company.com"
git config user.name "Your Work Name"

Automating with includeIf

For a more automated approach, use Git's conditional includes in ~/.gitconfig:

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

Use Case

Developers who contribute to both personal open-source projects and private company repositories on GitHub using separate accounts.

Try It — SSH Config Generator

Open full tool