Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Complete Tutorial: Use Two GitHub Accounts on One Mac with SSH

This tutorial explains how to configure two GitHub accounts on the same MacBook using separate SSH keys, without repeatedly switching accounts or breaking your existing Git configuration.

We’ll use your existing setup as the example:

  • Account 1: Your existing GitHub account, using ~/.ssh/id_ed25519
  • Account 2: rajeshkumarin, using ~/.ssh/id_ed25519_rajeshkumarin
  • Operating system: macOS
  • Terminal: Zsh
  • Goal: Use both accounts for cloning, pulling, pushing, and committing code.

1. Understand how it works

Your MacBook

One computer · Two GitHub identities

SSH Key 1

~/.ssh/id_ed25519

Account 1

SSH Key 2

~/.ssh/id_ed25519_rajeshkumarin

Account 2

GitHub

SSH aliases select the correct key automatically.

The key idea is that both accounts connect to github.com. Your local SSH configuration uses different aliases to choose the appropriate key.

2. Step 1 — Check your existing SSH keys

Open Terminal and run:

ls -la ~/.ssh

Your files may look like this:

~/.ssh/
├── config
├── id_ed25519
├── id_ed25519.pub
├── id_ed25519_rajeshkumarin
└── id_ed25519_rajeshkumarin.pubCode language: JavaScript (javascript)

The private keys are the files without .pub. The .pub files are the public keys that you add to GitHub.

Check whether both key files exist:

ls -l ~/.ssh/id_ed25519*Code language: JavaScript (javascript)

If your existing key has a different filename, keep that filename in the configuration rather than renaming or replacing it.

Important: Never share or upload your private SSH keys. Only the public keys should be added to GitHub.

3. Step 2 — Generate a second key (only if needed)

You already have a key named id_ed25519_rajeshkumarin, so skip this step if that key is valid and you intend to use it.

Otherwise, generate a new key:

ssh-keygen -t ed25519 \
  -C "second-email@example.com" \
  -f ~/.ssh/id_ed25519_rajeshkumarinCode language: JavaScript (javascript)

Replace second-email@example.com with the email associated with your second GitHub account.

If prompted for a passphrase, using one is recommended. Store it securely.

4. Step 3 — Add the public key to the second GitHub account

Copy the public key to your Mac clipboard:

pbcopy < ~/.ssh/id_ed25519_rajeshkumarin.pubCode language: JavaScript (javascript)

Next:

GitHubのSSH key作成と設定方法|くま

1. Open GitHub SSH settings

Go to GitHub → SSH and GPG keys. Make sure you are logged in to the second account.

1Password に SSH 接続もコミット署名も管理してもらおう

2. Add the key

Click New SSH key.

  • Title: MacBook Account 2
  • Key type: Authentication Key
  • Key: Paste the copied public key.

การ Setup Git และ GitHub ให้พร้อมสำหรับการทำงานร่วมกับทีม | 🚀 เส้นทางโปรแกรมเมอร์

3. Save the key

Click Add SSH key and complete any verification requested by GitHub.

GitHub permits the same public key to be used only once across accounts. Keep your first account’s existing key registered there, and register the second public key with the second account.

5. Step 4 — Configure SSH for both accounts

This is the most important step. Your Mac needs to know which SSH key to use for each GitHub account.

Open your SSH configuration file:

vi ~/.ssh/configCode language: JavaScript (javascript)

Replace the contents with the following configuration, assuming your first key is id_ed25519:

# GitHub Account 1
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes
    AddKeysToAgent yes
    UseKeychain yes

# GitHub Account 2
Host github-account2
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_rajeshkumarin
    IdentitiesOnly yes
    AddKeysToAgent yes
    UseKeychain yesCode language: PHP (php)

Save the file in Vim:

  1. Press Esc.
  2. Type :wq.
  3. Press Enter.

Understand the configuration

SettingPurpose
Host github.comAlias for Account 1
Host github-account2Alias for Account 2
HostName github.comActual GitHub server
IdentityFilePrivate key to use
IdentitiesOnly yesPrevents SSH from trying unrelated keys
AddKeysToAgent yesAdds the key to the SSH agent
UseKeychain yesSupports macOS Keychain integration

Important: github-account2 is a local alias, not a real hostname or GitHub username. Both aliases connect to github.com. This follows GitHub’s documented approach for selecting separate SSH keys. GitHub Docs+1

6. Step 5 — Set correct SSH file permissions

Run:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/config
chmod 600 ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519_rajeshkumarin
chmod 644 ~/.ssh/id_ed25519.pub
chmod 644 ~/.ssh/id_ed25519_rajeshkumarin.pub

These commands protect your private keys and configuration file.

If your first private key has a different filename, adjust the command accordingly.

7. Step 6 — Add both keys to the SSH agent

Start the SSH agent:

eval "$(ssh-agent -s)"Code language: JavaScript (javascript)

Add the first key:

ssh-add --apple-use-keychain ~/.ssh/id_ed25519Code language: JavaScript (javascript)

Add the second key:

ssh-add --apple-use-keychain ~/.ssh/id_ed25519_rajeshkumarinCode language: JavaScript (javascript)

Check which keys are loaded:

ssh-add -l

You should see fingerprints for your loaded keys.

If you get Could not open a connection to your authentication agent, run the first command again before adding the keys.

8. Step 7 — Test both GitHub accounts

Test Account 1:

ssh -T git@github.comCode language: CSS (css)

Expected response:

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

Test Account 2:

ssh -T git@github-account2Code language: CSS (css)

Expected response:

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

The greeting should identify the correct account for each command.

GitHub’s SSH test may exit with status code 1 even when authentication succeeds, because GitHub does not provide interactive shell access. The greeting is the important part. GitHub Docs+1

If the wrong account appears, or authentication fails, see the troubleshooting section below.

9. Step 8 — Clone repositories using either account

Once authentication works, use the corresponding SSH alias when cloning.

Account 1

git clone git@github.com:OWNER/REPOSITORY.gitCode language: PHP (php)

Uses ~/.ssh/id_ed25519.

Account 2 — rajeshkumarin

git clone git@github-account2:rajeshkumarin/REPOSITORY.gitCode language: PHP (php)

Uses ~/.ssh/id_ed25519_rajeshkumarin.

Replace OWNER and REPOSITORY with the actual repository owner and name.

For example, if your second account owns a repository called my-laravel-app:

git clone git@github-account2:rajeshkumarin/my-laravel-app.gitCode language: PHP (php)

For a private repository, the selected account must have permission to access it.

10. Step 9 — Configure an existing repository

You don’t need to clone a repository again if it already exists on your Mac. Change its remote URL instead.

First, enter the repository directory:

cd /path/to/your/repository

Check the current remote:

git remote -v

If it should use Account 2, run:

git remote set-url origin git@github-account2:OWNER/REPOSITORY.gitCode language: JavaScript (javascript)

Verify the change:

git remote -v

You should see github-account2 in the remote URL.

For Account 1, use git@github.com:OWNER/REPOSITORY.git instead.

This setting is stored in that repository’s .git/config, so changing one repository’s remote won’t change the others.

11. Step 10 — Configure Git commit names and email addresses

This step is separate from SSH authentication.

SSH decides which GitHub account authenticates when you push. Git’s user.name and user.email decide the author identity recorded in your commits.

For a repository belonging to Account 1:

git config user.name "Your Name"
git config user.email "first-email@example.com"Code language: CSS (css)

For a repository belonging to Account 2:

git config user.name "Rajesh Kumar"
git config user.email "second-email@example.com"Code language: CSS (css)

Use the appropriate name and email for each account.

These commands configure the identity only for the current repository because they omit --global.

Verify the settings:

git config user.name
git config user.emailCode language: CSS (css)

You can also inspect the configuration source:

git config --show-origin --get user.emailCode language: JavaScript (javascript)

For commits to appear as verified or linked to the intended GitHub profile, use an email associated with that account, or its GitHub-provided noreply email address.

12. Step 11 — Push and pull using the correct account

Once the repository’s remote and commit identity are configured, normal Git commands work as usual.

git status
git add .
git commit -m "Update application"
git push origin main
git pull origin mainCode language: JavaScript (javascript)

You don’t need to specify the SSH key on every command. The remote alias selects the correct key automatically.

Make sure main is the correct branch for your repository.

13. Common problems and solutions

ErrorLikely causeSolution
Could not resolve hostname rajeshkumarinUsername was used as the hostnameSet HostName github.com and connect using git@github-account2
Permission denied (publickey)Public key missing from GitHub, wrong key, or SSH configuration issueVerify the public key, alias, and IdentityFile
Wrong username in SSH greetingWrong key is being selectedCheck the Host alias and IdentityFile
Repository not foundIncorrect repository path or insufficient accessVerify the owner, repository name, and permissions
Permission denied when pushingAccount lacks write access, or branch protection blocks the pushCheck repository access and branch rules
Key is already in useSame public key was added to another GitHub accountGenerate a unique key for the second account
Bad configuration option: UseKeychainSSH client does not support that optionCheck the SSH client; on macOS, try adding IgnoreUnknown UseKeychain under the relevant host entry

Debug an SSH connection

If Account 2 still fails, run:

ssh -vT git@github-account2Code language: CSS (css)

Look for a line similar to:

Offering public key: /Users/rajesh/.ssh/id_ed25519_rajeshkumarinCode language: JavaScript (javascript)

That confirms which key SSH is attempting to use. If the wrong key is offered, check the SSH configuration. If the right key is offered but rejected, verify that its matching public key is registered with the correct GitHub account.

14. Quick reference: All important commands

List SSH keys Copy

ls -la ~/.ssh

Edit SSH config Copy

vi ~/.ssh/config

Load Account 1 key Copy

ssh-add –apple-use-keychain ~/.ssh/id_ed25519

Load Account 2 key Copy

ssh-add –apple-use-keychain ~/.ssh/id_ed25519_rajeshkumarin

Test Account 1 Copy

ssh -T git@github.com

Test Account 2 Copy

ssh -T git@github-account2

Clone Account 1 repo Copy

git clone git@github.com:OWNER/REPOSITORY.git

Clone Account 2 repo Copy

git clone git@github-account2:OWNER/REPOSITORY.git

Check repository remote Copy

git remote -v

Check commit email Copy

git config user.email

Final checklist

Setup verification

0 of 6Both SSH private keys exist on my Mac.Each public key is added to the correct GitHub account.The SSH config uses HostName github.com for both aliases.Both SSH authentication tests greet the correct usernames.Each repository uses the correct SSH remote URL.Each repository has the correct Git commit name and email.

For official reference, see GitHub’s guide to managing multiple accounts and generating and adding SSH keys on macOS.

The key takeaway: Keep your existing SSH key for Account 1, use id_ed25519_rajeshkumarin for Account 2, and use github-account2 in repository URLs whenever you want Git to authenticate as rajeshkumarin.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Master Catalogue: Process Maturity Models, Standards and Frameworks

The key is to document each framework accurately: not every standard has maturity levels, and we shouldn’t invent levels for frameworks that don’t define them. Here’s the…

Read More

ASPICE, SPICE, CMMI and Other Process Maturity Frameworks: A Complete Guide

Meta Title: ASPICE vs SPICE vs CMMI: Complete Guide to Process Maturity Models Meta Description: Learn about ASPICE, SPICE, CMMI, TMMi, ISO standards, cybersecurity frameworks, IT governance…

Read More

Software Process Improvement and Maturity Frameworks: The Complete Guide to ASPICE, SPICE, CMMI, ISO/IEC 330xx, TMMi, and More

A practical, step-by-step guide to understanding, assessing, implementing, and continuously improving software engineering processes using 10 industry-recognized maturity frameworks. A software development team can deliver releases every…

Read More

What Game Server Hosting Teaches You About DevOps

My first real DevOps lesson didn’t come from a course. It came from eight friends yelling in Discord because our Minecraft server had been down for three…

Read More

Top 10 Identity Verification (IDV) Tools: Features, Pros, Cons & Comparison

Introduction Identity Verification (IDV) tools are digital solutions designed to confirm that a person is who they claim to be. These tools typically verify government-issued identity documents,…

Read More

What a Third-Party Risk Program Should Cover in a Modern Stack

A modern third-party risk program must track more than vendor questionnaires and annual reviews. External providers connect to systems, data, infrastructure, and business operations, so their exposure…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x