Brand logoobin
ProjectsInsightsContact
Resume

2020 © Shahadat Robin

Configure Multiple SSH Keys on one computer (Linux)

Configure Multiple SSH Keys on one computer (Linux)
Author Shahadat Robin's Image

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.

Check for existing SSH keys.

Before generating anything new, confirm what you already have.

  • Open your terminal.
  • Run ls -al ~/.ssh to see if existing SSH keys are present.
$ ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist

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

  • id_rsa.pub
  • id_ecdsa.pub
  • id_ed25519.pub
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.

Generate Separate SSH Keys for Each Account

Instead of reusing one key everywhere, generate dedicated keys for each host or account.

Work GitHub 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

Personal GitHub Account

ssh-keygen -t ed25519 -C "your-personal-email@example.com"

Save it as: ~/.ssh/personal_github

Bitbucket Account

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.

Add Keys to the SSH Agent

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_bitbucket

You can verify added keys by: ssh-add -l

Add Public Keys to Their Respective Platforms

Each .pub file must be added to the correct account.

Example:

cat ~/.ssh/work_github.pub

Then:

  • Add the work key to company’s GitHub account
  • Add the personal key to personal GitHub account
  • Add the Bitbucket key to Bitbucket account

Navigate to:

Settings → SSH and GPG Keys → New SSH Key

Paste and save. Do not mix them up. That mistake costs time.

Configure the SSH Config File

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_bitbucket

This file is the silent conductor. Without it, SSH guesses. With it, SSH knows.

Test the Configuration

Test each connection:

ssh -T git@github-work
ssh -T git@github-personal
ssh -T git@bitbucket-work

If configured correctly, you should see a successful authentication message. If not — question the config file first. It is almost always the config.

Update Git Remote URLs.

Instead of using:

git@github.com:username/repo.git

Use your defined Host alias:

Work GitHub

git@github-work:username/repo.git

Personal GitHub

git@github-personal:username/repo.git

Bitbucket

git@bitbucket-work:username/repo.git

You can update an existing repo with:

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

Final Thoughts

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

Related