Saturday, October 10, 2026

Configure two GitHub accounts on the same Ubuntu machine

 

You can configure two GitHub accounts on the same Ubuntu machine without affecting your existing repositories.

Step 1: Check your existing SSH keys

Run:

ls -la ~/.ssh/

Check whether you already have an SSH key for your ORG GitHub account.

Step 2: Generate a separate SSH key 

If you don't already have one, run:

ssh-keygen -t ed25519 -C "your-org-email@org.edu.kw" -f ~/.ssh/id_ed25519_org

Press Enter when prompted for a passphrase if you don't want one, although using a passphrase is more secure.

This creates:

~/.ssh/id_ed25519_org
~/.ssh/id_ed25519_org.pub

Step 3: Add the SSH key to your ORG GitHub account

Display your public key:

cat ~/.ssh/id_ed25519_org.pub

Copy the output.

  1. Log in to your organization GitHub account.
  2. Open https://github.com/settings/keys
  3. Click New SSH key.
  4. Title: org Ubuntu Laptop
  5. Paste the public key.
  6. Click Add SSH key.

Do not upload or share your private key (id_ed25519_org).

Step 4: Configure both GitHub accounts

Open the SSH configuration:

nano ~/.ssh/config

Add:

Host github-org
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_org
    IdentitiesOnly yes

Keep any existing configuration unchanged.

Save using Ctrl + O, Enter, then Ctrl + X.

Step 5: Test ORG GitHub authentication

Run:

ssh -T git@github-org

Expected output:

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

If GitHub asks you to confirm the host fingerprint, verify it matches GitHub's published fingerprint before accepting.

Step 6: Clone your org project repository

Now run:

cd /var/www/html
git clone git@github-org:Org-Repo/project.git

This will use your ORG GitHub account instead of your existing account.

If ORG uses SAML SSO, you may also need to authorize the new SSH key for the organization.

Step 7: Verify

cd /var/www/html/project
git remote -v

Expected:

origin  git@github-org:ORG-Repo/project.git (fetch)
origin  git@github-org:ORG-Repo/project.git (push)

Your existing GitHub repositories will continue using their current authentication settings.


No comments:

Post a Comment