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:
- Eliminates browser-based logins and token juggling
- Avoids conflicts when switching between multiple GitHub accounts
- Provides a secure, persistent way to push and pull code
- Keeps personal and work repositories cleanly separated
๐ Final Working Solution Overview
We'll:
- Create separate SSH keys for each GitHub account.
- Add those keys to the corresponding GitHub accounts.
- Configure an SSH
configfile to manage multiple SSH identities. - Set local Git username and email per repository.
- Change existing remote URLs from HTTPS to SSH.
- Troubleshoot any permission denied or SSH agent errors.
๐๏ธ 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:
- Use different filenames via
-f ~/.ssh/your_key_name. - Email IDs used here don't need to match the GitHub account email exactly โ itโs just for annotation, but it's cleaner if they do.
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)
- Press Ctrl + X (to exit)
- If it asks Save modified buffer? (Y/N), press: Y to save changes N to discard changes
- Then press Enter to confirm the file name (if you chose to save)
(In Vim)
- Press Esc
- 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.emailhere must be a verified email on the GitHub account you're pushing to. Theuser.nameis 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:
- 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
- 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
- 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
- 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
- Go to GitHub Settings โ SSH and GPG keys
- Find the key you want to delete.
- Click Delete next to it.
๐ Setting Up SSH for a Team of Developers
When youโre working in a team, each member should:
- Generate their own SSH key pair
- Add their public SSH key to their personal GitHub account
- Clone the shared repository via SSH
- Set their per-repo Git config with a verified email in their GitHub account
- 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:
| Purpose | Email required | Must match GitHub account? | Why? |
|---|---|---|---|
1๏ธโฃ SSH key generation (-C flag) | โ Recommended | No (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) | โ Required | Yes | This 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 | โ Required | Yes | This is your account email (or additional verified emails on your account) that GitHub uses to link commits and notifications. |
NOTE:
- Email used in git config must be a verified email in the corresponding GitHub account.
- SSH key
-Cemail is optional for functionality, but should match for clarity. - Git username (
git config user.name) is for your local commits' author field and doesn't have to match your GitHub profile name โ though itโs good practice to keep it consistent.
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:
| Part | Meaning |
|---|---|
ssh-keygen | The 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:
~/.ssh/github_anyuserโ the private key (keep this secret)~/.ssh/github_anyuser.pubโ the public key (this goes into GitHub)
๐ฏ Why Use Each Option?
- โ
-t ed25519: Faster, safer, and smaller than RSA. Supports modern cryptography. - โ
-C: Helps you recognize which key is for what โ especially useful when managing multiple keys. - โ
-f: Allows you to name and organize your keys separately per GitHub account or project, instead of overwriting the defaultid_ed25519key.
๐ Example Without Flags (What Happens?)
If you just ran:
ssh-keygen
- It would default to
rsa(on older systems) ored25519(on newer). - Ask you interactively where to save the key (default
~/.ssh/id_ed25519) - No comment would be added.
๐ Pro Tip:
Always explicitly define:
- the key type
-t - the comment
-C - the filename
-f
โฆ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:
- Define custom Host aliases for different SSH destinations
- Specify which private key to use for which host
- Control other connection options (like port, user, etc.)
Even without IdentitiesOnly yes, the config file will:
- Map a host alias (like
github-anyuser) to a real hostname (github.com) - Set the corresponding
IdentityFilefor that host alias
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 theIdentityFileyou specified in the config.
Which can lead to:
- Authentication failures if the wrong key gets offered first and the server rejects it
- Or unnecessary key attempts before the correct one is picked
๐ ๐ฆ Example โ Without IdentitiesOnly yes
Config
Host github-anyuser HostName github.com User git IdentityFile ~/.ssh/id_ed25519_anyuser
What happens when you connect?
-
SSH will offer the key specified in
IdentityFile -
But will also try:
- Any keys in your SSH agent (
ssh-add -l) - And any default keys in
~/.ssh/(likeid_ed25519,id_rsa)
- Any keys in your SSH agent (
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?
- SSH will only use the specified key
- It will ignore all other keys in your agent and
.ssh/folder for this connection โ Clean, predictable, and avoids โPermission denied (publickey)โ errors
๐ ๐ So Whatโs the Point of ~/.ssh/config Without It?
Without IdentitiesOnly yes, the config is still useful for:
- Defining aliases (
Host github-anyuser) - Pointing to preferred keys via
IdentityFile - Setting custom usernames, ports, or other connection options
But โ to fully control which key gets used exclusively for a given host alias, you need IdentitiesOnly yes.
๐ โ TL;DR:
| Action | Config Only | Config + 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
- You donโt need to use the same email ID everywhere โ but it's recommended for clarity.
- You must configure per-repo Git user.name and user.email.
- SSH remote URLs must use the correct SSH alias from your SSH config.
- Always test connections with
ssh -Tbefore pushing code. - Switch existing HTTPS remotes to SSH with
git remote set-url. - Keep SSH keys unique and labeled for each GitHub account.
- Use separate SSH keys for each GitHub account
- Use per-repo
git configforuser.emailmatching a verified email on the corresponding account git config user.nameis for commit authorship display and can differ- Manage SSH identities with an SSH config file
- Team members should each use their own SSH key and GitHub account โ permissions are handled via GitHub settings, not by sharing keys
- No browser-based login needed
- No credential conflicts
- Clean per-project Git identity
๐ 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:
- Per-project
.git/configsetup - Directory-based
includeIfconfiguration - Using
core.sshCommandfor key management

