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

4
  • 1
    Where are your log entries for gitea? Where is the output of ssh -vvv gitea? Commented Jun 28, 2023 at 10:15
  • 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? Commented Jun 28, 2023 at 10:36
  • @user1686 I did specify that, but didn't show it in the question. Updated. Thanks. Commented Jun 28, 2023 at 10:53
  • @symcbean Updated with logs. Commented Jun 28, 2023 at 11:01

1 Answer 1

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 
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. Commented Jul 6, 2023 at 10:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.