【问题标题】:ssh on gitea with docker使用 docker 在 gitea 上 ssh
【发布时间】:2019-06-24 18:55:03
【问题描述】:

我刚刚在 Linux mint 19 上使用 docker 安装了 gitea,我使用 /data 和旧的 gitea 安装,所以我有一个填充数据库和存储库。当我访问网络时,它似乎可以正常工作。

问题在于使用 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

我检查了目录和文件/var/lib/gitea/ssh 的权限,但它似乎是正确的。 drwx-------rw-------

【问题讨论】:

    标签: docker ssh gitea


    【解决方案1】:

    启动docker容器时需要暴露ssh端口22,试试:

    docker run --expose 22 ...
    

    或者甚至更好地将EXPOSE 22 添加到 Dockerfile 并按照official docs 修复 SSH 登录:

    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"]
    

    【讨论】:

    • 很高兴听到我能够帮助您。你能接受我的回答并投票吗?谢谢!
    • 对不起,我不能投票,因为我没有足够的声誉。
    • 没问题,我很高兴我能提供帮助:)
    • 大家好,感谢两位的问答。 Docker Gitea 的问题是当你从容器中expose 22 时,你不能在主机服务器上使用相同的端口 22,因为它被 sshd 使用,但是你将它暴露给 222。这导致了我认为的其他问题,因为当您在服务器上使用除 22 之外的任何其他端口时,您不能简单地使用 gitea,但您需要在 .ssh/config 文件中输入一个条目来指定 ssh 连接的端口。您对此有任何解决方法或解决方案吗?
    猜你喜欢
    • 2021-05-26
    • 2021-01-30
    • 2015-01-18
    • 2018-08-24
    • 2018-09-09
    • 2017-11-06
    • 1970-01-01
    • 2020-03-04
    • 2021-04-27
    相关资源
    最近更新 更多