Re: When using several ssh key, Git match ssh key by host, instead of hostname in ssh config file.
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 26, 2023, 15:56 UTC
- Message-ID
- <xmqqk019cmss.fsf@gitster.g>
- In-Reply-To
- <OSYP286MB0215D880FA9D82B74E393DD691CF9@OSYP286MB0215.JPNP286.PROD.OUTLOOK.COM>
Yangyang Hua <hyy_41@live.com> writes:
Show 5 quoted lines
> 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_222so 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.