Below is a complete step-by-step guide to set up multiple SSH keys for different GitHub accounts/organizations on a Linux server.


📖 Complete Guide — Set Up Multiple SSH Keys for GitHub (Personal & Organization)


🔧 Step 1 — Check Existing SSH Keys

Check if any keys already exist:

ls -al ~/.ssh

If you see:

id_rsa
id_rsa.pub

These are your current keys (likely linked to kumar-maruti).


🔧 Step 2 — Generate New SSH Key for Motosharein

Run:

ssh-keygen -t rsa -b 4096 -C "abhisheksingh.cotocus@gmail.com"

When asked:

Enter file in which to save the key (/root/.ssh/id_rsa):

👉 Enter:

/root/.ssh/motoshare_rsa

When asked for a passphrase, press Enter to leave it empty (recommended for automation):

Enter passphrase (empty for no passphrase): (just press Enter)

This creates:

  • Private key: /root/.ssh/motoshare_rsa
  • Public key: /root/.ssh/motoshare_rsa.pub

🔧 Step 3 — Add Public Key to GitHub (Motosharein Account)

1️⃣ Show the Public Key

cat ~/.ssh/motoshare_rsa.pub

2️⃣ Copy the Key (starts with ssh-rsa)

3️⃣ Add Key to GitHub

  • Login to Motosharein’s GitHub account.
  • Go to: https://github.com/settings/ssh/new
  • Title: Motosharein Server Key
  • Key Type: Authentication Key
  • Paste the copied key.
  • Click Add SSH Key.

🔧 Step 4 — Create SSH Config to Manage Multiple Keys

Create or edit your SSH config file:

nano ~/.ssh/config

Add this content (customized for your case):

# Default GitHub account (kumar-maruti)
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa

# Motosharein GitHub account (for motoshares-web repo)
Host github-motoshare
    HostName github.com
    User git
    IdentityFile ~/.ssh/motoshare_rsa
  • Save file: Press CTRL+O, Enter.
  • Exit nano: Press CTRL+X.

🔧 Step 5 — Test Both SSH Configurations

Test kumar-maruti (Personal Account)

ssh -T git@github.com

Expected:

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

Test Motosharein (Organization)

ssh -T github-motoshare

Expected:

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

🔧 Step 6 — Clone Repository Using Correct Key

Since you now have two keys, you must:

  • Use git@github.com: for your personal repos (kumar-maruti).
  • Use git@github-motoshare: for Motosharein repos.

Clone the motoshare-web repo like this:

git clone git@github-motoshare:Motosharein/motoshare-web.git

This forces Git to use the correct key (motoshare_rsa) for this repo.


Full Summary Table

StepCommand/Action
1. Check Existing Keysls -al ~/.ssh
2. Generate New Keyssh-keygen -t rsa -b 4096 -C "email@example.com"
3. Save Key As/root/.ssh/motoshare_rsa
4. Show Public Keycat ~/.ssh/motoshare_rsa.pub
5. Add Key to GitHubGitHub Settings → SSH Keys
6. Create SSH ConfigEdit ~/.ssh/config
7. Test Personal Keyssh -T git@github.com
8. Test Organization Keyssh -T github-motoshare
9. Clone Repogit clone git@github-motoshare:Motosharein/motoshare-web.git

📥 Want This as a Ready-to-Use Script?

I can write a shell script (setup-ssh-keys.sh) that:

  • Generates the key.
  • Creates the ~/.ssh/config.
  • Displays the key to copy to GitHub.
  • Runs the SSH test commands automatically.

💬 Let me know if you want the automated script!

Would you like me to prepare this? 😊

Related Post

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x