Score:-1

SSH config for two daemons on same server

cn flag

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

ws flag
Where are your log entries for gitea? Where is the output of `ssh -vvv gitea`?
user1686 avatar
fr flag
Are you specifying the correct _username_ for the Gitea connection? I assume it expects you to log in as the user `git`, not as your regular account?
lonix avatar
cn flag
@user1686 I did specify that, but didn't show it in the question. Updated. Thanks.
lonix avatar
cn flag
@symcbean Updated with logs.
Score:0
cu flag
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
lonix avatar
cn flag
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.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.