2

I am trying to connect to my local Gitea server. I have set it up to use the integrated SSH server on port 2222. I am running Windows. Gitea is running fine.

Now I want to connect using Cygwin's git. For testing the connection to my repository I am using the ls-remote command which works fine if I use the GIT_SSH_COMMAND option like this:

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

Next I want to simplify life using ~/.ssh/config:

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

However, this does fail with error Unable to open connection:

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

Problem: IdentityFile is not applied. This works:

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

I am certain though, that my ~/.ssh/config is correct, because connecting via directly ssh -vv gitea works. Output (extract):

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

So why is git not using IdentityFile from ~/.ssh/config?

Jack Miller
  • 155
  • 1
  • 7

1 Answers1

3

It turned out that setting GIT_SSH_COMMAND="ssh" was enough. This means that git was using some other SSH client. Probably the one of OpenSSH which happened to be on the system path:

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

I fixed the issue by adding export GIT_SSH_COMMAND="/usr/bin/ssh" to ~/.bash_profile

Jack Miller
  • 155
  • 1
  • 7
  • This worked for me... I was using Window's Git command on my cygwin command line (as I checked what git it was using by trying 'which git') and realized maybe its not using the ssh command i want. just adding this GIT_SSH_COMMAND="ssh" env var worked for me – armyofda12mnkeys May 28 '21 at 17:34