Accessing a git repo via SSH "does not appear to be a git repository" - Stack Overflow

admin2025-04-29  1

Here is the config in the client: ~/.ssh/config

Host myserver
  HostName 172.2.1.1
  User git
  Port 22
  IdentityFile ~/.ssh/id_ed25519_repo1

The keys are added and veried successfully through the gitea web (SSH Keys).

The matter is I can't access a gitea repo like this:

git ls-remote myserver:user1/repo1.git
git ls-remote git@myserver:user1/repo1.git

// error:

fatal: '/user1/repo1.git' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

But the following accesses are no problem (no password prompted):

ssh git@myserver

git ls-remote http://ip:3000/user1/repo1.git

git ls-remote git@ip:user1/repo1.git

So what are possible solutions for this?

Here is the config in the client: ~/.ssh/config

Host myserver
  HostName 172.2.1.1
  User git
  Port 22
  IdentityFile ~/.ssh/id_ed25519_repo1

The keys are added and veried successfully through the gitea web (SSH Keys).

The matter is I can't access a gitea repo like this:

git ls-remote myserver:user1/repo1.git
git ls-remote git@myserver:user1/repo1.git

// error:

fatal: '/user1/repo1.git' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

But the following accesses are no problem (no password prompted):

ssh git@myserver

git ls-remote http://ip:3000/user1/repo1.git

git ls-remote git@ip:user1/repo1.git

So what are possible solutions for this?

Share Improve this question asked Jan 7 at 0:59 SteveHSteveH 2635 silver badges16 bronze badges 12
  • 1 The home directory of user git on 172.2.1.1 is probably / and there is no user1/repo1.git there. If it exists somwhere else on that machine (perhaps in /home?) try making that the home directory of user git (or changing the path used with the git commandline) – Chris Dodd Commented Jan 7 at 1:11
  • Note that 172.2.1.1 is not a private ip address (like 172.16.*..172.31.* are) -- it is the public address of 172-2-1-1.lightspeed.dybhfl.sbcglobal.net in Florida(db-ip.com/172.2.1.1) – Chris Dodd Commented Jan 7 at 1:13
  • @ChrisDodd The IP I picked is just an illustration. The point is the repo1 path is literal existing that both accessing using explit IP via HTTP and SSH work normally but via SSH host alias "myserver" does not. – SteveH Commented Jan 7 at 1:33
  • I'm not 100% familiar with gitea: gitea is the ssh server, am I correct? – LeGEC Commented Jan 7 at 4:32
  • @LeGEC Sure! "ssh -v myserver" works well. The absolute path doesn't work and doesn't intend to do with gitea. I am new to gitea also. – SteveH Commented Jan 7 at 5:12
 |  Show 7 more comments

1 Answer 1

Reset to default 1

I found the cause. It looks a trivial issue but not easy to realize.

First, I will explain each command why it works or doesn't work.

  • The following works because only SSH shell access is related, nothing to do with git.

    ssh git@myserver

  • The following works because git does not use SSH.

    git ls-remote http://ip:3000/user1/repo1.git

  • The following works because git+SSH loads "~/.ssh/id_ed25519" implicitly that I mistakenly thought the key should be "id_ed25519_repo1", in addition the key "id_ed25519" was configured via gitea web UI previously.

    git ls-remote git@ip:user1/repo1.git

  • The following do not work because git+SSH loads "~/.ssh/id_ed25519_repo1" explicitly - the key was added to authorized_keys manually.

    git ls-remote myserver:user1/repo1.git git ls-remote git@myserver:user1/repo1.git

So just adding a bare entry to the file like below, accessing "ssh user1@myserver" or "ssh user1@real-ip" will work well, but git+SSH absolutely does not work.

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIvf4l5RjqWL+kOnxpqhhGAIcIkWVSHqLbgkAzMAlYGm user1@domain

The reason is the missing a part that links SSH key to the git operations that explains why SSH auth is OK but git does not recognized the repo path. So the correct syntax to connect git to SSH should look like below:

command="/usr/local/bin/gitea --config=/etc/gitea/app.ini serv key-6",no-port-forwarding,no-X11-forwarding,no-user-rc,no-pty,restrict ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIvf4l5RjqWL+kOnxpqhhGAIcIkWVSHqLbgkAzMAlYGm user1@domain

It is quite long to manually edit, it'd better to let gitea adding that for us via web UI. But one issue appears, since the "command" comes in, the SSH shell access using "user1" becomes impossible. I don't know how to enable access via both git+SSH and SSH for the same user. My solution is to create a new key for pure SSH access or consider enable the PasswordAuthentication option.

Notes I want to share:

  • From a hint of @grawity_u1686 I use command "ssh -T -v git@myserver" to realize the implicit keys loaded. Thanks @grawity_u1686 and others.
  • During configure keys via gitea web UI, the generated signature is required by running: echo -n 'ff5338f9...' | ssh-keygen -Y sign -n gitea -f path-to-private-key In my Windows PC the generated signature always fail the verification, but successfully when I did it in Linux.
转载请注明原文地址:http://anycun.com/QandA/1745936294a91354.html