Trouble trying to clone repo with SSH

Hi all and thank you for any advice i will be getting!

i was setting up gitea on my qnap NAS via this tutorial:

after setting up a user account and repo, i tried to clone and got this:

$ git clone git@localhost:drjstudios/Samsara_UE.git
Cloning into 'Samsara_UE'...
ssh: connect to host localhost port 22: Connection refused
fatal: Could not read from remote repository.

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

i have set up the SSH key and verified it in gitea.

and my server config settings are as follows:

also when running

ssh localhost -vvv

i get this:

$ ssh localhost -vvv
OpenSSH_9.1p1, OpenSSL 1.1.1s  1 Nov 2022
debug1: Reading configuration data /etc/ssh/ssh_config
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/c/Users/user/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/c/Users/user/.ssh/known_hosts2'
debug2: resolving "localhost" port 22
debug3: resolve_host: lookup localhost:22
debug3: ssh_connect_direct: entering
debug1: Connecting to localhost [::1] port 22.
debug3: set_sock_tos: set socket 4 IPV6_TCLASS 0x48
debug1: connect to address ::1 port 22: Connection refused
debug1: Connecting to localhost [127.0.0.1] port 22.
debug3: set_sock_tos: set socket 4 IP_TOS 0x48
debug1: connect to address 127.0.0.1 port 22: Connection refused
ssh: connect to host localhost port 22: Connection refused

I had turned off my firewall when doing this if that helps.

i will any instructions explained to me as someone completely new as i am not familiar with where i should be running commands (esp on the NAS, on my windows machine i have limited experience using cmd and git bash). any help would be great, thanks!

The linked tutorial sets up SSH server at port 222 instead of default 22, which explains the “Connection refused” errors you are receiving. They simply mean that there is no application/server listening on port 22. You should currently be able to clone with command git clone ssh://git@localhost:222/drjstudios/Samsara_UE.git.

Since you do not have qnap’s SSH server enabled, it is pretty straight forward to fix this issue. You can simply change Docker configuration to put Gitea’s SSH server at 22 instead of 222, like so:

...
    volumes:
      - /share/docker-data/gitea-server:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "3000:3000"
      - "22:22" # I changed from 222:22 to 22:22
...

You will have to restart container after making this change.

Note it will become more difficult if you want to enable qnap’s SSH server later and have them both run at port 22. You will have to follow SSH Container Passthrough guide. Alternatively, you could run qnap’s SSH server at port 222 instead.

thanks jake for the reply!

i first tried your suggestion for changing the Docker configuration via editing the application as shown and then the gitea app could no longer start:

then i wiped everything and installed gitea again, then tried to clone again with your command and this happened:

$ git clone ssh://git@localhost:222/ROOT/Samsara_UE.git
Cloning into 'Samsara_UE'...
ssh: connect to host localhost port 222: Connection refused
fatal: Could not read from remote repository.

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

and checking the localhost again gives me this:

$ ssh localhost -vvv
OpenSSH_9.1p1, OpenSSL 1.1.1s  1 Nov 2022
debug1: Reading configuration data /etc/ssh/ssh_config
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/c/Users/user/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/c/Users/user/.ssh/known_hosts2'
debug2: resolving "localhost" port 22
debug3: resolve_host: lookup localhost:22
debug3: ssh_connect_direct: entering
debug1: Connecting to localhost [::1] port 22.
debug3: set_sock_tos: set socket 4 IPV6_TCLASS 0x48
debug1: connect to address ::1 port 22: Connection refused
debug1: Connecting to localhost [127.0.0.1] port 22.
debug3: set_sock_tos: set socket 4 IP_TOS 0x48
debug1: connect to address 127.0.0.1 port 22: Connection refused
ssh: connect to host localhost port 22: Connection refused

finally if i tried to check for ssh://git@localhost:222:

$ ssh ssh://git@localhost:222 -vvv
OpenSSH_9.1p1, OpenSSL 1.1.1s  1 Nov 2022
debug1: Reading configuration data /etc/ssh/ssh_config
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/c/Users/user/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/c/Users/user/.ssh/known_hosts2'
debug2: resolving "localhost" port 222
debug3: resolve_host: lookup localhost:222
debug3: ssh_connect_direct: entering
debug1: Connecting to localhost [::1] port 222.
debug3: set_sock_tos: set socket 4 IPV6_TCLASS 0x48
debug1: connect to address ::1 port 222: Connection refused
debug1: Connecting to localhost [127.0.0.1] port 222.
debug3: set_sock_tos: set socket 4 IP_TOS 0x48
debug1: connect to address 127.0.0.1 port 222: Connection refused
ssh: connect to host localhost port 222: Connection refused


Ah, I think I see the problem now. I had assumed you were running the git clone command on the computer that is running Gitea, but I think you are cloning from a separate computer. Since Gitea failed to run after changing port mapping, I think qnap’s SSH server is enabled so there are a few options:

  • You can just clone/pull/push with HTTP
  • You can just clone/pull/push with SSH on port 222 like git clone ssh://git@[insert qnap computer's IP]:222/drjstudios/Samsara_UE.git.
  • You can setup SSH Container Passthrough as linked above
  • You can change qnap’s SSH port to something other than 22, and move Gitea’s SSH to port 22

Localhost/ 127.x.x.x IPs all refer to the local computer, so localhost on my machine will go to my machine, localhost on your machine goes to your machine. You will have to substitute it for the IP address of your qnap system, so for example git clone ssh://git@192.168.1.208:222/drjstudios/Samsara_UE.git (you will have to find IP from qnap, probably on some network page).

  • You can just clone/pull/push with SSH on port 222 like git clone ssh://git@[insert qnap computer's IP]:222/drjstudios/Samsara_UE.git.

this worked, thank you so much jake!

yes i did not mention that i was in fact trying to clone from another computer and using the qnap only as a git server. sorry about that!

going forward perhaps doing the passthrough will be the best course of action but i guess i can leave that for another time. Thank you again!