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:
forMotosharein
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
Step | Command/Action |
---|---|
1. Check Existing Keys | ls -al ~/.ssh |
2. Generate New Key | ssh-keygen -t rsa -b 4096 -C "email@example.com" |
3. Save Key As | /root/.ssh/motoshare_rsa |
4. Show Public Key | cat ~/.ssh/motoshare_rsa.pub |
5. Add Key to GitHub | GitHub Settings → SSH Keys |
6. Create SSH Config | Edit ~/.ssh/config |
7. Test Personal Key | ssh -T git@github.com |
8. Test Organization Key | ssh -T github-motoshare |
9. Clone Repo | git 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? 😊