Setup Multiple GitHub SSH Keys


๐Ÿ› ๏ธ Setup Multiple GitHub SSH Keys on macOS (Different Email/Account)

โœ… 1. Generate a New SSH Key

ssh-keygen -t ed25519 -C "new_email@example.com" -f ~/.ssh/id_ed25519_new
  • Private key: ~/.ssh/id_ed25519_new

  • Public key: ~/.ssh/id_ed25519_new.pub


โœ… 2. Add the New Key to the SSH Agent

eval "$(ssh-agent -s)"
ssh-add --apple-use-keychain ~/.ssh/id_ed25519_new

If the above fails:

ssh-add ~/.ssh/id_ed25519_new

โœ… 3. Add Public Key to GitHub

Copy the key:

pbcopy < ~/.ssh/id_ed25519_new.pub

Then go to your GitHub Account > Settings > SSH and GPG Keys
โ†’ Click New SSH Key โ†’ Paste โ†’ Save


โœ… 4. Configure SSH for Multiple GitHub Accounts

Edit your SSH config:

nano ~/.ssh/config

Paste this configuration:

# Default GitHub account
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519
  IdentitiesOnly yes

# Second GitHub account (new email)
Host github-new
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_new
  IdentitiesOnly yes

โœ… 5. Clone Repos from New Account

git clone git@github-new:username/repo.git

Or change remote on an existing repo:

git remote set-url origin git@github-new:username/repo.git

๐ŸŽฏ Bonus: Set Local Git Email Per Project

git config user.name "Your New GitHub Name"
git config user.email "new_email@example.com"

To persist this only in the current repo:

git config --local user.name "Your New GitHub Name"
git config --local user.email "new_email@example.com"

Follow me on medium : @sweetnandha.cse

1
Subscribe to my newsletter

Read articles from Nandhakumar Murugan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nandhakumar Murugan
Nandhakumar Murugan

An enthusiast software developer, having more than 6+ yrs of experience. Enjoy greatly working in client-side programming and UI stuff (Web & Mob applications). Core strength in java, C#, .net core, Javascript, AngularJs upto latest, Nativescript with angular and Flutter.