

Shahadat Robin
Software Developer, LemonHive
9 months ago
Hello! This is a quick guide for those who need to set up multiple SSH keys for multiple hosts. I was inspired to write this article as I suffered upon some issues when setting up multiple SSH keys. My company uses private Github and Bitbucket accounts, and for my personal use, I have a public Github account. So, I have to need access from one PC.
If you don’t know what an SSH key is or why it is used, you can check out this article to learn more about them.
Here are the steps that I took to set it up.
Before generating anything new, confirm what you already have.
ls -al ~/.ssh to see if existing SSH keys are present.$ ls -al ~/.ssh
# Lists the files in your .ssh directory, if they existCheck the directory listing to see if you already have a public SSH key. By default, the filenames of supported public keys for GitHub are one of the following.
If you receive an error that ~/.ssh doesn't exist, you do not have an existing SSH key pair in the default location. You can create a new SSH key pair in the next step.Instead of reusing one key everywhere, generate dedicated keys for each host or account.
ssh-keygen -t ed25519 -C "your-work-email@company.com"When prompted for the file name, do not press enter. Instead, specify a custom name: ~/.ssh/work_github
ssh-keygen -t ed25519 -C "your-personal-email@example.com"Save it as: ~/.ssh/personal_github
ssh-keygen -t ed25519 -C "your-work-email@company.com"Save it as: ~/.ssh/work_bitbucket
Now you have clear separation. No overlap. No identity confusion.
Start the SSH agent:
eval "$(ssh-agent -s)"Then add your keys:
ssh-add ~/.ssh/work_github
ssh-add ~/.ssh/personal_github
ssh-add ~/.ssh/work_bitbucketYou can verify added keys by: ssh-add -l
Each .pub file must be added to the correct account.
Example:
cat ~/.ssh/work_github.pubThen:
Navigate to:
Settings → SSH and GPG Keys → New SSH Key
Paste and save. Do not mix them up. That mistake costs time.
Now comes the most important step. Create or edit: ~/.ssh/config
Add entries like this:
# Work GitHub
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/work_github
# Personal GitHub
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/personal_github
# Work Bitbucket
Host bitbucket-work
HostName bitbucket.org
User git
IdentityFile ~/.ssh/work_bitbucketThis file is the silent conductor. Without it, SSH guesses. With it, SSH knows.
Test each connection:
ssh -T git@github-work
ssh -T git@github-personal
ssh -T git@bitbucket-workIf configured correctly, you should see a successful authentication message. If not — question the config file first. It is almost always the config.
Instead of using:
git@github.com:username/repo.gitUse your defined Host alias:
git@github-work:username/repo.gitgit@github-personal:username/repo.gitgit@bitbucket-work:username/repo.gitYou can update an existing repo with:
git remote set-url origin git@github-work:username/repo.gitManaging multiple SSH keys is not difficult — but it requires intention.
Separate identities, Clear configuration, Explicit host mapping.
Set separate identity as per project - Inside each repository, configure the correct user identity:
git config user.name "Your Name"
git config user.email "your-work-email@company.com"Once set up correctly, everything feels clean. Pushes go where they should. Commits carry the right signature. Access works without friction.
If you’re working across multiple accounts from one machine, this setup isn’t optional. It’s essential.
Configure once. Think clearly. Move faster.
