I'm trying to understand how the configurations under .ssh/config and .git/config interact.
Here's the situation: I have two separate github accounts, let's call them GH0 and GH1, and I want to interact with both "passwordlessly", i.e., using ssh keys in ~/.ssh/id_rsa.GH0.pub
and ~/.ssh/id_rsa.GH1.pub
. At the moment this works for GH0 but not for GH1. (E.g., push
commands to GH1 die with ERROR: Repository not found.\nfatal: The remote end hung unexpectedly.
; ssh -T git@github.com
works, but only because it connects GH0
.)
This means that for each of these github accounts I have to have a corresponding section in ~/.ssh/config, specifying which ssh key file to use for it. (E.g., the section for GH0 will have something like IdentityFile ~/.ssh/id_rsa.GH0
, etc.)
The question is: what else do I have to put in each of these sections? More specifically,
what do I have to put as the argument to the
Host
keyword in~/.ssh/config
?
The information that I've found so far on this makes no sense to me. In some examples, I see stuff like
Host github.com
Hostname github.com
User git
IdentityFile ~/.ssh/id_rsa
Host ac2.github.com
Hostname github.com
User git
IdentityFile ~/.ssh/id_rsa_ac2
Where does that "ac2." prefix in the second Host
come from???
Where do I find the corresponding ones for my github accounts?
Some of the info I've found lead one to guess that arguments to the Host
keyword are in fact arbitrary, implying that the following would be fine too
Host omgwtfbbq
Hostname github.com
User git
IdentityFile ~/.ssh/GH0
Host 4.8.15.16.23.42
Hostname github.com
User git
IdentityFile ~/.ssh/GH1
But if so, this raises yet another question: How does git
(or github) know which of these two sections to use for any given command?
Again, I guess1 that this would be specified in the project's .git/config
file, under some [remote ...]
section, but how?
1I must resort to guessing because, for one thing, I have not been able to find documentation for the interpretation of the key-value pairs in .git/config. The closest I've found is the man page for git-config, but I can't find any documentation in this page for the url = ...
field under a [remote ...]
section. The man page for git-remote, too, has no documentation about this field.