Re: When using several ssh key, Git match ssh key by host, instead of hostname in ssh config file.
From: Yangyang Hua <hidden>
Date: 2023-01-27 02:03:03
Thank you! I understand this feature of ssh. ________________________________________ From: Junio C Hamano <redacted> on behalf of Junio C Hamano <redacted> Sent: Friday, 27 January 2023 12:56 am To: Yangyang Hua Cc: git@vger.kernel.org Subject: Re: When using several ssh key, Git match ssh key by host, instead of hostname in ssh config file. Yangyang Hua [off-list ref] writes:
Hi, I find when I use several ssh keys with the right config file and clone my private repo, git can't match the key by hostname. ... I think when git read ssh config, it uses host to match the key instead of hostname. Is this bug?
This useful feature is given by ssh, and Git does not deserve credit
for it. The config file of SSH allows you to write multiple entries
that points at the same host, e.g.
Host host1
HostName host.example.com
IdentityFile ~/.ssh/id_rsa_111
Host host2
HostName host.example.com
IdentityFile ~/.ssh/id_rsa_222
so that you can specify which key to use for the same destination
when you have more than one user there. "ssh host1" uses id_rsa_111
while "ssh host2" uses the other one, both connections going to the
same destination host.
If host.example.com were a hosting site like github.com, you can use this
feature to say
$ git push git@host1:/me/lesson1
to connect using id_rsa_111. If you use
$ git clone git@github.com:/me/lesson1
there is no clue which of the two entries you want to use.