git が ssh 構成ファイルで設定された ID を使用しないのはなぜですか?

git が ssh 構成ファイルで設定された ID を使用しないのはなぜですか?

ローカルに接続しようとしていますギテアサーバー。ポート 2222 の統合 SSH サーバーを使用するように設定しました。Windows を実行しています。Gitea は正常に動作しています。

今、私は接続したいCygwin の gitリポジトリへの接続をテストするために、ls-リモートコマンドは、GIT_SSH_COMMAND次のようなオプション:

GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa" git ls-remote --exit-code -h ssh://username@localhost:2222/username/Repo.git

次に、以下を使用して生活を簡素化したいと思います~/.ssh/config

host gitea
 HostName localhost
 Port 2222
 IdentityFile ~/.ssh/id_rsa
 User username

ただし、これはエラーで失敗しますUnable to open connection:

git ls-remote --exit-code -h ssh://gitea/username/Repo.git

問題:IdentityFile適用されません。これは機能します:

GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa" git ls-remote --exit-code -h ssh://gitea/username/Repo.git

~/.ssh/configただし、直接接続すると機能するので、私の方法が正しいことは確かですssh -vv gitea。出力 (抜粋):

[...]
debug1: Connecting to localhost [::1] port 2222.
debug1: Connection established.
[...]
debug1: Offering public key: RSA SHA256:XXX /home/username/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 535
debug2: input_userauth_pk_ok: fp SHA256:XXX
debug1: Authentication succeeded (publickey).
Authenticated to localhost ([::1]:2222).
[...]

では、なぜfrom をgit使用しないのでしょうか?IdentityFile~/.ssh/config

答え1

設定だけで十分であることがわかりましたGIT_SSH_COMMAND="ssh"。これは、git別の SSH クライアントを使用していたことを意味します。おそらく、システム パスにあった OpenSSH のクライアントでしょう。

$ whereis ssh
ssh: /usr/bin/ssh.exe /cygdrive/c/WINDOWS/System32/OpenSSH/ssh.exe /usr/share/man/man1/ssh.1.gz

export GIT_SSH_COMMAND="/usr/bin/ssh"追加することで問題を修正しました~/.bash_profile

関連情報