How to Properly Manage Multiple SSH Keys for Git on Your Local Environment

Photo by Yancy Min on Unsplash

Basic Use Case: deploy keys for a single repository

ssh-keygen -t ed25519 -C "email@example.com"
cd ~/.ssh/
git fetch
Deploy Keys on Github.com

Advanced Use Case: multiple deploy keys for multiple repositories

nano ~/.ssh/config
Host project1.github.com
Hostname github.com
IdentityFile ~/.ssh/key_project1
Host project2.github.com
Hostname github.com
IdentityFile ~/.ssh/key_project2
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
[remote "origin"]
url = git@project1.github.com:Cach54/project1.git
fetch = +refs/heads/*:refs/remotes/origin/*
git fetch

Troubleshooting

ssh-add -D
ssh -v git@github.com

What’s Next

Freelance IT Project Manager | Writer for The Startup and DataDrivenInvestor | 📍Paris

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store