I have generated distinct SSH keys for each account and successfully added them to their respective GitHub profiles. I’ve also created an SSH config file, but I think there’s something wrong with my configuration.
The main issue is that I can’t figure out the correct way to tell SSH which key to use for which account. I need id_rsa_primary to be used when accessing repositories from the first account, and id_rsa_secondary for the second account.
What’s the proper syntax for the SSH config file to handle this dual account setup? Any help would be appreciated.
Don’t forget to set up your Git config after the SSH stuff. I hit this annoying issue where my commits kept showing the wrong GitHub account even though SSH was working fine. You’ve got two options: either set git config user.name and git config user.email locally in each repo, or use conditional includes in your global config based on folder paths. Also, if you’re getting auth conflicts, make sure your SSH agent isn’t loading both keys at once. You can check which key it’s using with ssh -T git@github-primary and ssh -T git@github-secondary.
Manual SSH config works, but you’ll hit walls when switching projects or bringing on new team members. I’ve been there at work - automating this saves massive time.
The real issue isn’t just SSH keys. It’s the whole workflow. What happens when you need 20 repos across different accounts? Or auto-syncing commits between accounts?
I built something that handles this automatically. Detects which account owns the repo, grabs the right SSH key, sets proper git config, handles cloning. No more alias juggling or forgotten user.email settings.
Once it’s set up, it just works. Your team clones repos normally and automation handles everything else. Way better than remembering custom hostnames for every git command.
You can build similar stuff with Latenode - handles account detection logic and automates git operations seamlessly.
add IdentitiesOnly yes to each host block in your ssh config - without it, ssh tries all your keys and GitHub might lock u out. also update your existing remotes to use the new aliases instead of github.com
To configure SSH for two GitHub accounts, use host aliases in your ~/.ssh/config file. Specifically, set it up like this:
Host github-primary
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_primary
Host github-secondary
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_secondary
When cloning repositories, replace github.com with your assigned aliases. For example, use git@github-secondary:seconduser/repo.git for the second account. This method ensures SSH uses the correct key for each account.