How to Set up multiple SSH keys on one System
Tools & Apps

How to Set up multiple SSH keys on one System

In this guide, you’ll learn how to create separate SSH key pairs (using secure algorithms like Ed25519), lock down their permissions, and assign each one to a custom host alias in your ~/.ssh/config. You’ll then load these keys into the SSH agent for password-free authentication, register the public keys with Git and server accounts, and verify connections. This setup keeps personal, work, and open-source access neatly separated and secure.

Configuring multiple SSH keys was challenging because the required information was scattered across various sources. I’ve gathered it all here in one place to make the process easier and save you time.

Why Use Multiple SSH Keys?

Developers often juggle more than one Git or server account—personal repositories vs. work projects, open-source contributions vs. private servers, etc. Assigning a unique SSH key pair to each account helps:

  • Keep access separate (so you don’t accidentally push to the wrong repo)

  • Maintain security (if one key is compromised, others remain safe)

  • Automate connections via simple host aliases

Choose Your Algorithms and File Names

SSH keys can be generated with different algorithms; Ed25519 is recommended for new keys due to its security and speed. For each identity, decide on a clear file name:

1# Personal (e.g. GitHub)
2ssh-keygen -t ed25519 -C "you@personal.email" -f ~/.ssh/id_ed25519_personal
3
4# Work (e.g. Bitbucket)
5ssh-keygen -t ed25519 -C "you@work.email"     -f ~/.ssh/id_ed25519_work
  • The -C flag adds a comment (your email) for easy identification.

  • The -f flag specifies the output filename, so you end up with two pairs.

    • ~/.ssh/id_ed25519_personal & ~/.ssh/id_ed25519_personal.pub

    • ~/.ssh/id_ed25519_work & ~/.ssh/id_ed25519_work.pub

Secure Your Private Keys

By default, SSH will warn if your private key is too exposed. Tighten permissions immediately:

1chmod 600 ~/.ssh/id_ed25519_personal
2chmod 600 ~/.ssh/id_ed25519_work

This ensures only your user account can read/write the private key files.

Create or Update Your SSH Config

The SSH config file (~/.ssh/config) lets you assign host aliases that map to specific keys:

1# ~/.ssh/config
2
3# Personal GitHub account
4Host github-personal
5    HostName github.com
6    User git
7    IdentityFile ~/.ssh/id_ed25519_personal
8    IdentitiesOnly yes
9
10# Work Bitbucket account
11Host bitbucket-work
12    HostName bitbucket.org
13    User git
14    IdentityFile ~/.ssh/id_ed25519_work
15    IdentitiesOnly yes
  • Host: the alias you’ll use in Git commands (e.g. github-personal).

  • HostName: the real server address (e.g. github.com).

  • IdentityFile: the path to the private key you generated.

  • IdentitiesOnly yes: forces SSH to use only the specified key, avoiding unintended key tried

Add Keys to the SSH Agent

If you use an SSH agent to cache decrypted keys, load them now so SSH can pick the right one automatically:

1# Start agent (if not already running)
2eval "$(ssh-agent -s)"
3
4# Add both keys
5ssh-add ~/.ssh/id_ed25519_personal
6ssh-add ~/.ssh/id_ed25519_work

You’ll be prompted for each key’s passphrase (if you set one). After this, the agent will serve the decrypted keys to SSH sessions.

Register Your Public Keys with Remote Accounts

For each account, copy the corresponding .pub file and paste it into the SSH key settings on the website:

1# Copy to clipboard on macOS/Linux
2pbcopy < ~/.ssh/id_ed25519_personal.pub
  • Go to GitHub → Settings → SSH and GPG keys and add the personal key.

  • Repeat for Bitbucket → Personal settings → SSH keys with the work key.

Cloning and Pushing via Host Aliases

Use your custom aliases when interacting with repos:

1# Clone your personal repo
2git clone git@github-personal:yourusername/your-repo.git
3
4# Clone your work repo
5git clone git@bitbucket-work:yourusername/work-project.git
6

Under the hood, SSH looks up github-personal in your ~/.ssh/config and uses the right key automatically.

Verification and Troubleshooting

  • List loaded keys: ssh-add -l

  • Test connection:

    1ssh -T git@github-personal
    2ssh -T git@bitbucket-work
  • “Permission denied” errors often mean either the wrong key is being offered or file permissions are too loose—double-check your config aliases and chmod settings.

Conclusion

With separate SSH key pairs, a well-configured ~/.ssh/config, and the SSH agent handling your keys, you can seamlessly switch between personal and work Git accounts—or any other SSH-based service—without conflict. This setup keeps your workflows clean, secure, and highly productive.

Author Picture

Vishal G.

Fulltime Developer, Part-time Blogger and Entrepreneur with over 9 years of experience in web development and a passion for sharing knowledge.