Setup Multiple GitHub SSH Keys

N
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.
🛠️ 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_newPublic 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"