SSH config - same host but different keys and usernames
Problem
I've set up two GitHub accounts, but I can't get ssh keys to work correctly. I've tried various configs. : Works for username1: at username2's repo: I've also tried with both and settings under same . The output is the same as with the last config. I think git automatically searches for Host "github.com" because the remote is such. It is said that Host can be anything you want (https://stackoverflow.com/a/3828682). Is there any way to change what Host from ssh config should specific repo use? It would be ideal if I could solve this just from ~/.ssh/config.
Error Output
Host github_username1
HostName github.com
IdentityFile ~/.ssh/rsa_1
User username1
Host github_username2
HostName github.com
IdentityFile ~/.ssh/rsa_2
User username2Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix for: SSH config - same host but different keys and usernames
Yes, only the section headers (the or lines) are searched for – everything else is only applied as a setting. In other words, if you connect to , OpenSSH will only look for a section titled . So if you have , you must use this exact same "hostname" in your Git remotes as well. OpenSSH will not find this section if you use git@github.com. However, that is not what causes authentication failures. When connecting to GitHub via SSH, you must use as your username – the server will recognize you base…
Awaiting Verification
Be the first to verify this fix
Sign in to verify this fix