git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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_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.
Previous: Yangyang HuaNext: Yangyang Hua
Message 2 of 3 in “When using several ssh key, Git match ssh key by host, instead of hostname in ssh config file.”
  1. Yangyang HuaJan 26, 2023
  2. Junio C HamanoJan 26, 2023
  3. Yangyang HuaJan 27, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.