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_orgPress 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.pubStep 3: Add the SSH key to your ORG GitHub account
Display your public key:
cat ~/.ssh/id_ed25519_org.pubCopy the output.
- Log in to your organization GitHub account.
- Open https://github.com/settings/keys
- Click New SSH key.
- Title:
org Ubuntu Laptop - Paste the public key.
- 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/configAdd:
Host github-org
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_org
IdentitiesOnly yesKeep any existing configuration unchanged.
Save using Ctrl + O, Enter, then Ctrl + X.
Step 5: Test ORG GitHub authentication
Run:
ssh -T git@github-orgExpected 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.gitThis 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 -vExpected:
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