Multiple Git accounts are easiest to manage with one key per identity and SSH host aliases. Do not keep swapping the global Git configuration and hoping muscle memory selects the correct employer.
1. Generate separate keys
Prefer Ed25519 unless a legacy server requires RSA:
1 | ssh-keygen -t ed25519 -C "primary@example.com" -f ~/.ssh/github_primary |
Upload each .pub file to the matching Git provider account. Never upload or share the private-key file.
2. Add keys to the agent
1 | eval "$(ssh-agent -s)" |
ssh-agent is not a stack sent to the server. It is a local process that holds private keys and performs signing operations on behalf of SSH clients; the private key itself stays local.
3. Configure host aliases
1 | # ~/.ssh/config |
Protect the files:
1 | chmod 700 ~/.ssh |
IdentitiesOnly yes prevents SSH from offering every loaded key until the server gets bored and rejects the connection.
4. Use the alias in Git remotes
1 | git remote add origin git@github-primary:primary-user/project.git |
Test each identity:
1 | ssh -T git@github-primary |
Also set repository-local commit identity when needed:
1 | git config user.name "Hudson" |
SSH selects the account used to authenticate. Git’s user.name and user.email select the author written into commits. They are related, but they are not the same switch.