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"
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.