mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <>
To: Yangyang Hua <>
Cc: "" <>
Subject: Re: When using several ssh key, Git match ssh key by host, instead of hostname in ssh config file.
Date: Thu, 26 Jan 2023 07:56:03 -0800	[thread overview]
Message-ID: <xmqqk019cmss.fsf@gitster.g> (raw)
In-Reply-To: <OSYP286MB0215D880FA9D82B74E393DD691CF9@OSYP286MB0215.JPNP286.PROD.OUTLOOK.COM> (Yangyang Hua's message of "Thu, 26 Jan 2023 14:46:54 +0000")

Yangyang Hua <> 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
      IdentityFile ~/.ssh/id_rsa_111

    Host host2
      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 were a hosting site like, you can use this
feature to say

    $ git push git@host1:/me/lesson1

to connect using id_rsa_111.  If you use

    $ git clone

there is no clue which of the two entries you want to use.

  reply	other threads:[~2023-01-26 15:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-26 14:46 When using several ssh key, Git match ssh key by host, instead of hostname in ssh config file Yangyang Hua
2023-01-26 15:56 ` Junio C Hamano [this message]
2023-01-27  1:57   ` Yangyang Hua

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqk019cmss.fsf@gitster.g \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).