5

I just installed gitea using docker on Linux mint 19, I used /data with old gitea instalation so I have a populate db and repositories. It seems work correctly when I access to the web.

The problem is using SSH:

➜  /tmp sudo git clone git@gitealocal:felipe/test.git
Cloning into 'test'...
ssh: connect to host gitealocal port 22: Connection refused
fatal: Could not read from remote repository.

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


➜  /tmp ssh -vT gitealocal
OpenSSH_7.6p1 Ubuntu-4ubuntu0.1, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /home/felipe/.ssh/config
debug1: /home/felipe/.ssh/config line 16: Applying options for gitealocal
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to gitealocal [127.0.1.1] port 10022.
debug1: Connection established.
debug1: identity file /home/felipe/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /home/felipe/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/felipe/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/felipe/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/felipe/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/felipe/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/felipe/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/felipe/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.1
ssh_exchange_identification: Connection closed by remote host

I check permissions on directory and files /var/lib/gitea/ssh but it seems right. drwx------ and -rw-------

gogoigo
  • 53
  • 1
  • 4

1 Answers1

3

You need to expose the ssh port 22 when you start the docker container, try:

docker run --expose 22 ...

Or even better add EXPOSE 22 to the Dockerfile and the SSH login fix as per official docs:

FROM ubuntu:16.04

RUN apt-get update && apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:screencast' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
Exadra37
  • 11,244
  • 3
  • 43
  • 57
  • Nice to hear that I was able to help you. Can you please accept my answer and up vote it. Thanks! – Exadra37 Feb 02 '19 at 23:49
  • Sorry, I can't up vote it because I don't have enought reputation. – gogoigo Feb 08 '19 at 11:56
  • No problem and I am gald that I was able to help :) – Exadra37 Feb 08 '19 at 12:40
  • Hey guys, Thanks for the Q&A both. The problem with Docker Gitea is when you `expose 22` from container, you cannot use same port 22 on host server since its used by sshd, but you expose it let say to `222`. This is causing something else I think because when you use any other port then 22 on server, you cannot simply use gitea but you need an entry in `.ssh/config` file to specify the port for the ssh connection. Do you have any workaround or solution to this? – Güney Saramalı Feb 28 '22 at 13:35
  • https://docs.gitea.io/en-us/install-with-docker/#sshing-shim-with-authorized_keys I finally found answer for port 22 with port forwarding if you guys interesting. – Güney Saramalı Mar 01 '22 at 19:44