โ˜ฐ
ร—

How to configure multiple Cloud Repositories account in one machine

NOTE: In this article we will see the steps for GitHub, but for other service providers the steps will be similar.

๐Ÿ“Œ How to Manage Multiple GitHub Accounts and Team SSH Access on One Machine

the cleanest and most reliable way is via SSH keys and per-repo Git config.

Managing multiple GitHub accounts on the same computer or coordinating a team using SSH can be tricky if youโ€™re not set up properly. In this guide, weโ€™ll walk you through a clean, scalable approach to handling multiple accounts with SSH, and how to onboard your whole team to push code securely via SSH.

๐Ÿš€ Complete Guide: Managing Multiple GitHub Accounts on One Computer Using SSH

When you work on multiple projects โ€” perhaps some personal, some for clients, or for different organizations โ€” you often need to push code to multiple GitHub accounts from a single machine. This setup can get tricky when the default GitHub authentication via browser or SSH conflicts between accounts.

In this article, Iโ€™ll walk you through a clean, effective way to configure multiple SSH keys on the same machine, assign them to different GitHub accounts, and manage them per project with ease. Weโ€™ll also cover common mistakes I faced, how to troubleshoot them, and best practices for configuring emails and usernames.


๐Ÿ“Œ Why Not Just Use Browser-Based Authentication?

Using browser-based authentication forces you to use a single GitHub account in your default browser. If you work with multiple accounts, this creates conflicts โ€” either pushing code with the wrong identity or getting permission errors.

SSH keys solve this cleanly and securely.


๐ŸŽฏ Why Use SSH for GitHub?

Using SSH for authentication:


๐Ÿ“– Final Working Solution Overview

We'll:


๐ŸŽ›๏ธ Complete Step-by-Step Setup

NOTE: Try to run the below commands in the bash for better results.

1๏ธโƒฃ Generate SSH Keys for Each Account

Open your terminal and generate a unique SSH key pair for each GitHub account:

ssh-keygen -t ed25519 -C "anyuser625@gmail.com" -f ~/.ssh/github_anyuser ssh-keygen -t ed25519 -C "capscode.team@gmail.com" -f ~/.ssh/github_capscode

Key points:

It generates a new SSH key pair using the Ed25519 algorithm, adds a comment (email), and saves the key pair for each account in a specific file location. We will see the complete breakdown of this command below,

2๏ธโƒฃ Add SSH Keys to SSH Agent

Start the SSH agent:

eval "$(ssh-agent -s)"

Then add both keys:

ssh-add ~/.ssh/github_anyuser ssh-add ~/.ssh/github_capscode

Check if they're added:

ssh-add -l

3๏ธโƒฃ Add Public Keys to Respective GitHub Accounts

Copy each public key:

cat ~/.ssh/github_anyuser.pub cat ~/.ssh/github_capscode.pub

Go to GitHub โ†’ Settings โ†’ SSH and GPG keys for each account and add the corresponding key.


4๏ธโƒฃ Configure SSH Config File for Multiple Identities

Create (if it doesn't exist) or edit:

nano ~/.ssh/config

Add:

# anyuser GitHub account Host github-anyuser HostName github.com User git IdentityFile ~/.ssh/github_anyuser IdentitiesOnly yes # capscode GitHub account Host github-capscode HostName github.com User git IdentityFile ~/.ssh/github_capscode IdentitiesOnly yes

Note: Host github-anyuser , here the host name need not needs to be same as the key name. This is crucial. The Host alias (github-anyuser, github-capscode) is what youโ€™ll use in your remote URL instead of github.com. This lets you route SSH connections to the correct key.

To exit: (In Bash)

  1. Press Ctrl + X (to exit)
  2. If it asks Save modified buffer? (Y/N), press: Y to save changes N to discard changes
  3. Then press Enter to confirm the file name (if you chose to save)

(In Vim)

  1. Press Esc
  2. Then type: :wq and hit Enter to save and exit :q! and hit Enter to force quit without saving

5๏ธโƒฃ Test SSH Connections

For each account:

ssh -T git@github-anyuser ssh -T git@github-capscode

NOTE: Here github-anyuser is a host alias name (and not the keyname) you define in your ~/.ssh/config file. It acts like a nickname for a specific SSH config block โ€” pointing to github.com with a specific identity file. A successful message:

Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.

6๏ธโƒฃ Set Local Git Identity for Each Project

Git identity (username and email) can be different for each repository. Navigate to each projectโ€™s directory and run:

For personal projects:

git config user.name "User Name" git config user.email "anyuser625@gmail.com"

For capscode projects:

git config user.name "capscode" git config user.email "capscode.team@gmail.com"

โš ๏ธ Important: This avoids commits showing up under the wrong GitHub user. The user.email here must be a verified email on the GitHub account you're pushing to. The user.name is a local author name for commits โ€” it doesnโ€™t need to match your GitHub profile name, but good practice says it should.

List Config in a Project To check config in a repo:

git config --list --local

7๏ธโƒฃ Switch Remote URL from HTTPS to SSH

If you have cloned the repo using SSH, then no need to follow this step.

Navigate to your local repo, if your projectโ€™s remote origin is still HTTPS like:

https://github.com/capscode/capscode-website.git

Change it to the correct SSH alias like:

git remote set-url origin git@github-capscode:capscode/capscode-website.git

Mistake I Made: Initially, I was using git@github.com:... โ€” but it should be your SSH alias, e.g., git@github-capscode:... as per ~/.ssh/config.


8๏ธโƒฃ Verify Your Remote URL

Check:

git remote -v

It should look like:

origin  git@github-capscode:capscode/capscode-website.git (fetch)
origin  git@github-capscode:capscode-website.git (push)

9๏ธโƒฃ Troubleshooting Common Issues

โœ… Permission Denied (publickey) Check which keys are active:

ssh-add -l

If missing, re-add:

ssh-add ~/.ssh/github_capscode

โœ… Testing Connection Verbosely

ssh -vT git@github-capscode ssh -T git@github.com

โœ… If SSH Key Shows 'Never Used' in GitHub This typically means it hasn't been used yet โ€” try a git pull or git push after ensuring the remote URL and SSH config are correct.


How to remove an SSH key both locally from your machine and optionally from GitHub too, if needed.

๐Ÿ“Œ To Remove an SSH Key from Your Local Machine:

  1. Delete the private & public key files

Letโ€™s say your key was:

~/.ssh/github_anyuser
~/.ssh/github_anyuser.pub

Remove them like this:

rm ~/.ssh/github_anyuser rm ~/.ssh/github_anyuser.pub

  1. Remove the key from the SSH agent (if it was added)

List keys loaded in SSH agent:

ssh-add -l

Remove a specific key:

ssh-add -d ~/.ssh/github_anyuser

Or remove all keys:

ssh-add -D

  1. Update your ~/.ssh/config (if you configured one)

Open your SSH config:

nano ~/.ssh/config

Remove or comment out the section referring to the deleted key:

# Host github-personal # HostName github.com # User git # IdentityFile ~/.ssh/github_anyuser
  1. Verify Removal

Check if the SSH key is still available locally:

ls ~/.ssh/

Check active keys in your SSH agent:

ssh-add -l

And thatโ€™s it โ€” clean removal done!


๐Ÿ“Œ To Remove an SSH Key from GitHub Account

  1. Go to GitHub Settings โ†’ SSH and GPG keys
  2. Find the key you want to delete.
  3. Click Delete next to it.

๐Ÿ“Œ Setting Up SSH for a Team of Developers

When youโ€™re working in a team, each member should:

  1. Generate their own SSH key pair
  2. Add their public SSH key to their personal GitHub account
  3. Clone the shared repository via SSH
  4. Set their per-repo Git config with a verified email in their GitHub account
  5. Each Member Configures SSH (optional if default key is used), If the member generated a custom-named key, like id_ed25519_john, theyโ€™ll need to configure their ~/.ssh/config else not

๐Ÿ”‘ Developer SSH Key Generation:

ssh-keygen -t ed25519 -C "developer@example.com"

๐Ÿ“ฅ Add Public Key to GitHub:

Go to Settings โ†’ SSH and GPG keys โ†’ New SSH key

๐Ÿ”— Clone the Shared Repo:

git clone git@github.com:organization/repo.git

๐Ÿ‘ฅ Manage Permissions via GitHub:

Use GitHub repo settings (or organization/team permissions) to control access.

โšก Bonus: Verify Connection

Each member can verify their SSH setup with:

ssh -T git@github.com

It should respond:

Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.

NOTE: SSH key management is local to their machine; access control is managed via GitHub

๐Ÿ“Œ Do the email addresses need to be the same in:

PurposeEmail requiredMust match GitHub account?Why?
1๏ธโƒฃ SSH key generation (-C flag)โœ… RecommendedNo (but good practice)This is a label in the SSH key's public file โ€” itโ€™s purely informational and doesn't affect GitHub authentication.
2๏ธโƒฃ Per-repo Git identity (git config user.email)โœ… RequiredYesThis email is embedded in each commitโ€™s metadata. GitHub uses this to associate commits with your account. Must be a verified email on that account for verified commits and contribution tracking.
3๏ธโƒฃ GitHub account emailโœ… RequiredYesThis is your account email (or additional verified emails on your account) that GitHub uses to link commits and notifications.

NOTE:


Awesome question โ€” letโ€™s carefully break down every flag and argument in this command:


๐Ÿ“Œ Full Command:

ssh-keygen -t ed25519 -C "anyuser625@gmail.com" -f ~/.ssh/github_anyuser

๐Ÿ“– What ssh-keygen -t ed25519 -C "anyuser625@gmail.com" -f ~/.ssh/github_anyuser command does:

It generates a new SSH key pair using the Ed25519 algorithm, adds a comment (email), and saves the key pair in a specific file location.


๐Ÿ“Œ Breakdown of Each Flag and Argument:

PartMeaning
ssh-keygenThe command-line tool for generating, managing, and converting SSH key pairs.
-t ed25519-t specifies the type of key to create.
ed25519 is a modern, fast, and secure elliptic-curve algorithm recommended over RSA now.
-C "anyuser625@gmail.com"-C adds a comment inside the public key file.
Typically used to indicate the email or purpose of the key.
This makes it easier to identify the key later when viewing public keys on GitHub or in ~/.ssh/authorized_keys.
-f ~/.ssh/github_anyuser-f specifies the filename and location where to save the key pair.
It saves the private key at ~/.ssh/github_anyuser and the public key at ~/.ssh/github_anyuser.pub.
If omitted, it defaults to ~/.ssh/id_ed25519.

๐Ÿ“ฆ What Files Are Created?

After running this:


๐ŸŽฏ Why Use Each Option?


๐Ÿ” Example Without Flags (What Happens?)

If you just ran:

ssh-keygen

๐Ÿ“Œ Pro Tip:

Always explicitly define:

โ€ฆwhen working with multiple keys to avoid confusion later.


How SSH behaves with multiple keys in the agent

When you connect to a host (e.g., github.com), SSH will try all keys loaded in the agent, one by one, until one works or all fail.

This can work fine if the server accepts the key early, but:

It might slow down the connection because SSH tries multiple keys.

Some servers (including GitHub and Bitbucket) have a limit on how many keys they accept in one authentication attempt.

If the wrong key is tried first and rejected, sometimes you get โ€œPermission deniedโ€ errors.

Why you still want an SSH config file The config file with IdentityFile and IdentitiesOnly yes tells SSH exactly which key to try for which host.

This prevents SSH from trying every key in the agent blindly.

It speeds up authentication and avoids key conflicts or permission errors.

๐Ÿ“Œ So, Whatโ€™s the Use of the ~/.ssh/config File If We Donโ€™t Mention IdentitiesOnly yes?

The ~/.ssh/config file allows you to:

Even without IdentitiesOnly yes, the config file will:

But hereโ€™s the subtle catch:

๐Ÿ›‘ Without IdentitiesOnly yes โ€” SSH will still offer other keys loaded in your SSH agent or found in default locations alongside the IdentityFile you specified in the config.

Which can lead to:


๐Ÿ“Œ ๐Ÿ“ฆ Example โ€” Without IdentitiesOnly yes

Config

Host github-anyuser HostName github.com User git IdentityFile ~/.ssh/id_ed25519_anyuser

What happens when you connect?

This can cause issues if the wrong key gets tried first.


๐Ÿ“Œ ๐Ÿ“ฆ Example โ€” With IdentitiesOnly yes

Config

Host github-anyuser HostName github.com User git IdentityFile ~/.ssh/id_ed25519_anyuser IdentitiesOnly yes

What happens now?


๐Ÿ“Œ ๐Ÿ” So Whatโ€™s the Point of ~/.ssh/config Without It?

Without IdentitiesOnly yes, the config is still useful for:

But โ€” to fully control which key gets used exclusively for a given host alias, you need IdentitiesOnly yes.


๐Ÿ“Œ โœ… TL;DR:

ActionConfig OnlyConfig + IdentitiesOnly yes
Define Host aliasesโœ…โœ…
Specify which key should be preferredโœ…โœ…
Restrict SSH to use only that keyโŒโœ…

Note: IdentitiesOnly yes makes that preference mandatory


๐Ÿ“Œ ๐Ÿ’ก Pro Tip:

If you only have one key in your agent and one in your .ssh/ folder โ€” the config without IdentitiesOnly yes works fine. But in multi-key, multi-host setups (like multiple GitHub/Bitbucket/GitLab accounts) โ€” itโ€™s essential.

โœ… Final Summary


๐ŸŽ‰ Done!

Now you can cleanly push code to multiple GitHub accounts from one machine without conflicts or permission errors.

๐Ÿ”„ Alternative Approaches

Git Configuration Methods

If you prefer managing identities through Git configuration rather than SSH aliases, check out our companion guide:

Modern way to manage multiple cloud repositories from one machine
Learn about: