git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* When using several ssh key, Git match ssh key by host, instead of hostname in ssh config file.
@ 2023-01-26 14:46 Yangyang Hua
  2023-01-26 15:56 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Yangyang Hua @ 2023-01-26 14:46 UTC (permalink / raw)
  To: git@vger.kernel.org

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 try ssh-add command to add the keys. "ssh -T git@github.com" can work, but git clone/push/pull these action display "Permission denied (publickey)".
Test in git version 2.38.1.windows.1 with win10 and git version 2.34.1 with Ubuntu 22.04.1 LTS
I check the -v and -vvv log, git does read my config file in ~/.ssh.

After I change the repo address to host("github") in my ssh config file, i can clone the repo and push/pull.
Host github
  HostName github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_rsa_111
So I change the host to "github.com" in ssh config, everything is back to normal.
Host github.com
  HostName github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_rsa_111

 I think when git read ssh config, it uses host to match the key instead of hostname. Is this bug?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: When using several ssh key, Git match ssh key by host, instead of hostname in ssh config file.
  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
  2023-01-27  1:57   ` Yangyang Hua
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2023-01-26 15:56 UTC (permalink / raw)
  To: Yangyang Hua; +Cc: git@vger.kernel.org

Yangyang Hua <hyy_41@live.com> 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: When using several ssh key, Git match ssh key by host, instead of hostname in ssh config file.
  2023-01-26 15:56 ` Junio C Hamano
@ 2023-01-27  1:57   ` Yangyang Hua
  0 siblings, 0 replies; 3+ messages in thread
From: Yangyang Hua @ 2023-01-27  1:57 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git@vger.kernel.org

Thank you!
I understand this feature of ssh.

________________________________________
From: Junio C Hamano <jch2355@gmail.com> on behalf of Junio C Hamano <gitster@pobox.com>
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 <hyy_41@live.com> 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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-27  2:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2023-01-27  1:57   ` Yangyang Hua

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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).