the wiki of cscosine
This guide explains how to configure multiple GitHub accounts on the same machine using SSH so that each repository pushes with the correct account.
Example accounts:
personal_nameorganization_nameThis prevents accidental pushes with the wrong identity and ensures GitHub Actions shows the correct actor.
Create one SSH key per GitHub account.
Personal account:
ssh-keygen -t ed25519 -C "personal_name"
Save as:
~/.ssh/id_ed25519_personal
Organization account:
ssh-keygen -t ed25519 -C "organization_name"
Save as:
~/.ssh/id_ed25519_organization
Resulting directory structure:
~/.ssh/
id_ed25519_personal
id_ed25519_personal.pub
id_ed25519_organization
id_ed25519_organization.pub
Copy the public keys:
cat ~/.ssh/id_ed25519_personal.pub
cat ~/.ssh/id_ed25519_organization.pub
Add them to GitHub:
Account personal_name
Settings → SSH and GPG keys → New SSH key
Paste:
id_ed25519_personal.pub
Account organization_name
Settings → SSH and GPG keys → New SSH key
Paste:
id_ed25519_organization.pub
Edit or create:
~/.ssh/config
Example configuration:
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
IdentitiesOnly yes
Host github-organization
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_organization
IdentitiesOnly yes
This creates two SSH aliases:
github-personalgithub-organizationEach alias uses a different SSH key.
Verify each account works.
Test personal account:
ssh -T github-personal
Expected output:
Hi personal_name! You've successfully authenticated
Test organization account:
ssh -T github-organization
Expected output:
Hi organization_name! You've successfully authenticated
Set the repository remote to the correct SSH alias.
Repositories that should push as personal_name:
git remote set-url origin git@github-personal:OWNER/REPO.git
Repositories that should push as organization_name:
git remote set-url origin git@github-organization:OWNER/REPO.git
Example:
git remote set-url origin git@github-organization:organization_name/myrepo.git
This controls commit metadata (author name/email).
For organization repositories:
git config user.name "organization_name"
git config user.email "organization_email@example.com"
For personal repositories:
git config user.name "personal_name"
git config user.email "personal_email@example.com"
Check the configured remote:
git remote -v
Example output:
origin git@github-organization:organization_name/repo.git
Push a commit and verify on GitHub:
| Repository type | SSH alias | Push actor |
|---|---|---|
| personal repos | github-personal | personal_name |
| organization repos | github-organization | organization_name |
This setup ensures: