DEV Community

Munir Ahmad
Munir Ahmad

Posted on • Originally published at Medium on

Use Multiple GitHub Accounts on One Machine (SSH Keys, macOS & Linux)


A step-by-step guide to seamlessly manage multiple GitHub accounts with SSH keys.

Managing Multiple GitHub Accounts on One Machine Using SSH

If you use both personal and work GitHub accounts on the same machine, authentication issues are almost inevitable. Commits go to the wrong account, pushes fail, or Git keeps asking for credentials.

The clean solution is simple: one SSH key per account, configured once, and reused forever. This guide shows how to do exactly that.

What You’ll Learn

  • Create separate SSH keys for each GitHub account
  • Configure SSH to automatically select the correct identity
  • Clone, push, and commit without account conflicts

Applies to: macOS and Linux (Windows users via WSL or Git Bash can follow the same steps)

Prerequisites

  • Git installed
  • Basic terminal knowledge
  • Access to multiple GitHub accounts

Step 1: Generate a Dedicated SSH Key

Create a new key for your work account:

ssh-keygen -t ed25519 -C "work@email.com" -f ~/.ssh/id_ed25519_work
Enter fullscreen mode Exit fullscreen mode

This avoids overwriting existing keys and clearly separates identities.

When prompted, adding a passphrase is recommended for security.

Generated files:

  • id_ed25519_work — private key (keep secret)
  • id_ed25519_work.pub — public key (add to GitHub)

Step 2: Add the Key to the SSH Agent

Start the agent and load your key:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_work
Enter fullscreen mode Exit fullscreen mode

This allows Git to authenticate without repeatedly asking for a passphrase.

Step 3: Add the Public Key to GitHub

Copy your public key:

cat ~/.ssh/id_ed25519_work.pub
Enter fullscreen mode Exit fullscreen mode

Copy the entire output (starts with ssh-ed25519).

  1. Navigate to: https://github.com/settings/keys
  2. Click New SSH key
  3. Add a title (e.g., “Work Laptop — 2024”)
  4. Paste your public key
  5. Click Add SSH key


Highlighting where to add your SSH key in GitHub settings.

Step 4: Configure SSH Host Aliases

Edit your SSH config:

nano ~/.ssh/config
Enter fullscreen mode Exit fullscreen mode

Add:

# Here you can add multiple identities personal, work etc.
# Personal account
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519
  IdentitiesOnly yes

# Work account
Host github-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_work
  IdentitiesOnly yes
Enter fullscreen mode Exit fullscreen mode

This tells SSH exactly which key to use for each account.

Step 5: Test the Setup

ssh -T github-work
Enter fullscreen mode Exit fullscreen mode

If successful, GitHub will confirm authentication. Expected output:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.
Enter fullscreen mode Exit fullscreen mode

Using the Correct Account

Clone Repositories

# Work account
git clone git@github-work:company/repo.git

# Personal account
git clone git@github.com:username/repo.git
Enter fullscreen mode Exit fullscreen mode

Fix an Existing Repository

git remote set-url origin git@github-work:company/repo.git
Enter fullscreen mode Exit fullscreen mode

Set Commit Identity (Per Repository)

git config user.name "Your Name"
git config user.email "work@company.com"
Enter fullscreen mode Exit fullscreen mode

This ensures commits are attributed correctly.

Final Thoughts

Managing multiple GitHub accounts doesn’t require hacks or workarounds.

With one SSH key per account and a clear SSH configuration , Git becomes invisible — and that’s exactly how tooling should behave.

Configure it once. Forget about it forever.

Top comments (0)