-1

My server exposes two ssh ports: one for the server itself, and one for a git daemon (gitea).

My local ~/.ssh/config:

Host server
    hostname 1.2.3.4
    port 22
    user foo
    identityfile ~/.ssh/id_rsa_server
Host gitea
    hostname 1.2.3.4
    port 2222
    user git
    identityfile ~/.ssh/id_rsa_gitea

I can ssh into the server using $ ssh server.

But I cannot ssh or perform git operations using gitea - it returns public key errors. It seems to choose the wrong key, even though I specified it in the config file. I think it chooses the first in the list.

Workarounds:

  • $ GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_gitea -F /dev/null" git ...
  • $ git config core.sshCommand "ssh -i ~/.ssh/id_rsa_gitea -F /dev/null"; git ...

But I always forget those settings, and they don't work well with automation (I need to remember to set it for every repo, manually).

I prefer to fix the ~/.ssh/config file, so it works as expected. How can I do that?


UPDATE:
The verbose ssh log includes this:

debug1: Reading configuration data ~/.ssh/config
...
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: ~/.ssh/id_rsa_server RSA SHA256:... explicit agent
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
git@1.2.3.4: Permission denied (publickey).

So as I said above, it's only offering the first key, then fails. It's not offering the correct key (the second one in the config file).

lonix
  • 896
  • 10
  • 23

1 Answers1

0
Host server
    Hostname 1.2.3.4
    Port 22
    User foo
    IdentityFile ~/.ssh/id_rsa_server

Host gitea
    Hostname 1.2.3.4
    Port 2222
    User git
    IdentityFile ~/.ssh/id_rsa_gitea
    IdentitiesOnly yes
VSYS Host
  • 11
  • 1
  • That is the same as what I posted, except for the `IdentitiesOnly yes` line, which unfortunately doesn't solve the problem. SSH on the client doesn't offer that key, it always offers the first one in the list. – lonix Jul 06 '23 at 10:07