| When you use multiple RSA (SSH) keys for GitHub, you need to configure them properly so Git knows which key to use for which repository. This is common when you have multiple GitHub accounts (e.g., personal and work). Here’s how you can do it: 1. Generate Multiple SSH KeysIf you don’t already have them: ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
When prompted for filename, give each key a unique name: ~/.ssh/id_rsa_github_personal
~/.ssh/id_rsa_github_work
2. Add Keys to SSH Agenteval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa_github_personal
ssh-add ~/.ssh/id_rsa_github_work
3. Configure SSH (~/.ssh/config)Edit or create the SSH config file: nano ~/.ssh/config
Add entries for each GitHub account: # Personal GitHub
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_github_personal
# Work GitHub
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_github_work
4. Use the Correct Host in Your Git RemoteWhen cloning or setting remotes, use the alias (github-personal or github-work): # Personal repo
git clone git@github-personal:username/repo.git
# Work repo
git clone git@github-work:company/repo.git
If the repo is already cloned, update the remote: git remote set-url origin git@github-work:company/repo.git
5. Test Your Configssh -T git@github-personal
ssh -T git@github-work
You should see GitHub greeting you with the correct username for each. |