Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ubuntu SSH服务器不接受连接_Ubuntu_Ssh_Docker_Openssh - Fatal编程技术网

Ubuntu SSH服务器不接受连接

Ubuntu SSH服务器不接受连接,ubuntu,ssh,docker,openssh,Ubuntu,Ssh,Docker,Openssh,我使用Docker在本地构建了一个Docker映像,它运行一个SSH服务器+一些其他服务。Dockerfile是内部的,所以我不能在这里发布。但我做的基本事情是: RUN apt-get install -q -y openssh-server openssh-client RUN cp /etc/ssh/sshd_config /etc/ssh/sshd_config.factory-defaults RUN chmod a-w /etc/ssh/sshd_config.factory-d

我使用Docker在本地构建了一个Docker映像,它运行一个SSH服务器+一些其他服务。Dockerfile是内部的,所以我不能在这里发布。但我做的基本事情是:

RUN apt-get install -q -y openssh-server openssh-client

RUN cp /etc/ssh/sshd_config /etc/ssh/sshd_config.factory-defaults

RUN chmod a-w /etc/ssh/sshd_config.factory-defaults

RUN mkdir /var/run/sshd

RUN echo 'root:changeme' |chpasswd

ADD ./bootstrap.sh /root/bootstrap.sh

ENTRYPOINT ["sh", "/root/bootstrap.sh"]
和bootstrap.sh的内部:

...
echo "Starting SSH service..."
/usr/sbin/sshd -D > /dev/null 2>&1 &
ps -A | grep sshd
...
。。。到目前为止,它仍然有效我可以从主机连接到SSH服务器(在Ubuntu容器中运行)。

到目前为止,一切顺利。现在我已经把图片上传到Dockerhub,并在tutum.co上运行它

现在的问题是:SSH服务器启动了,但我无法连接到它。甚至是容器内部的局部。顺便说一下,我有一个浏览器外壳,所以我仍然能够执行命令

我在容器内部执行:

ssh root@localhost -v                        
OpenSSH_5.9p1 Debian-5ubuntu1.4, OpenSSL 1.0.1 14 Mar 2012                      
debug1: Reading configuration data /etc/ssh/ssh_config                          
debug1: /etc/ssh/ssh_config line 19: Applying options for *                     
debug1: Connecting to localhost [::1] port 22.                                  
debug1: Connection established.                                                 
debug1: permanently_set_uid: 0/0                                                
debug1: identity file /root/.ssh/id_rsa type -1                                 
debug1: identity file /root/.ssh/id_rsa-cert type -1                            
debug1: identity file /root/.ssh/id_dsa type -1                                 
debug1: identity file /root/.ssh/id_dsa-cert type -1                            
debug1: identity file /root/.ssh/id_ecdsa type -1                               
debug1: identity file /root/.ssh/id_ecdsa-cert type -1                          
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debia
n-5ubuntu1.4                                                                    
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1.4 pat OpenSSH*                     
debug1: Enabling compatibility mode for protocol 2.0                            
debug1: Local version string SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1.4            
debug1: SSH2_MSG_KEXINIT sent                                                   
Read from socket failed: Connection reset by peer 

您正在尝试以
根用户身份连接,这是容器中
/etc/ssh/sshd\u config
中禁止的标准选项。您需要在
Dockerfile
中设置
用户
,或者允许
root登录
,或者在
Dockerfile
中复制公钥。我不鼓励您允许
root
-登录,也不鼓励您通过
Dockerfile
复制公钥。我的解决方案是按以下方式编辑您的
Dockerfile

# Set root passwd
RUN echo 'root:changeme' |chpasswd

# Add user so that container does not run as root
RUN useradd -m michaelkunzmann
RUN echo "michaelkunzmann:test" | chpasswd
RUN usermod -s /bin/bash michaelkunzmann
RUN usermod -aG sudo michaelkunzmann
ENV HOME /home/michaelkunzmann
ENV HOSTNAME michaelkunzmannsbox
然后构建映像并通过
ssh登录michaelkunzmann@localhost-v
。(如果这不起作用,请确保您使用的是正确的
端口。
。您可以指定它,例如使用
docker run-d-p 127.0.0.1:5000:22-p--name=“命名您的容器!”您的图像。
。然后您可以通过
sshmichaelkunzmann@localhost-p 5000


顺便说一下,如果您正在容器中运行多个进程,您应该熟悉。

您正在尝试以
根用户身份连接,这是容器中
/etc/ssh/sshd\u config
中的标准选项。您需要在
Dockerfile
中设置
用户
,或者允许
root登录
,或者在
Dockerfile
中复制公钥。我不鼓励您允许
root
-登录,也不鼓励您通过
Dockerfile
复制公钥。我的解决方案是按以下方式编辑您的
Dockerfile

# Set root passwd
RUN echo 'root:changeme' |chpasswd

# Add user so that container does not run as root
RUN useradd -m michaelkunzmann
RUN echo "michaelkunzmann:test" | chpasswd
RUN usermod -s /bin/bash michaelkunzmann
RUN usermod -aG sudo michaelkunzmann
ENV HOME /home/michaelkunzmann
ENV HOSTNAME michaelkunzmannsbox
然后构建映像并通过
ssh登录michaelkunzmann@localhost-v
。(如果这不起作用,请确保您使用的是正确的
端口。
。您可以指定它,例如使用
docker run-d-p 127.0.0.1:5000:22-p--name=“命名您的容器!”您的图像。
。然后您可以通过
sshmichaelkunzmann@localhost-p 5000


顺便说一下,如果您正在容器中运行多个进程,您应该熟悉。

您正在尝试以
根用户身份连接,这是容器中
/etc/ssh/sshd\u config
中的标准选项。您需要在
Dockerfile
中设置
用户
,或者允许
root登录
,或者在
Dockerfile
中复制公钥。我不鼓励您允许
root
-登录,也不鼓励您通过
Dockerfile
复制公钥。我的解决方案是按以下方式编辑您的
Dockerfile

# Set root passwd
RUN echo 'root:changeme' |chpasswd

# Add user so that container does not run as root
RUN useradd -m michaelkunzmann
RUN echo "michaelkunzmann:test" | chpasswd
RUN usermod -s /bin/bash michaelkunzmann
RUN usermod -aG sudo michaelkunzmann
ENV HOME /home/michaelkunzmann
ENV HOSTNAME michaelkunzmannsbox
然后构建映像并通过
ssh登录michaelkunzmann@localhost-v
。(如果这不起作用,请确保您使用的是正确的
端口。
。您可以指定它,例如使用
docker run-d-p 127.0.0.1:5000:22-p--name=“命名您的容器!”您的图像。
。然后您可以通过
sshmichaelkunzmann@localhost-p 5000


顺便说一下,如果您正在容器中运行多个进程,您应该熟悉。

您正在尝试以
根用户身份连接,这是容器中
/etc/ssh/sshd\u config
中的标准选项。您需要在
Dockerfile
中设置
用户
,或者允许
root登录
,或者在
Dockerfile
中复制公钥。我不鼓励您允许
root
-登录,也不鼓励您通过
Dockerfile
复制公钥。我的解决方案是按以下方式编辑您的
Dockerfile

# Set root passwd
RUN echo 'root:changeme' |chpasswd

# Add user so that container does not run as root
RUN useradd -m michaelkunzmann
RUN echo "michaelkunzmann:test" | chpasswd
RUN usermod -s /bin/bash michaelkunzmann
RUN usermod -aG sudo michaelkunzmann
ENV HOME /home/michaelkunzmann
ENV HOSTNAME michaelkunzmannsbox
然后构建映像并通过
ssh登录michaelkunzmann@localhost-v
。(如果这不起作用,请确保您使用的是正确的
端口。
。您可以指定它,例如使用
docker run-d-p 127.0.0.1:5000:22-p--name=“命名您的容器!”您的图像。
。然后您可以通过
sshmichaelkunzmann@localhost-p 5000


顺便说一句,如果您正在容器中运行多个进程,您应该熟悉。

我的docker文件,以供像我这样的其他人参考:

FROM centos:6

RUN yum install -y openssh-server
RUN mkdir /var/run/sshd

RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key

RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config

RUN echo 'root:root' | chpasswd

CMD ["/usr/sbin/sshd", "-D"]

我的docker文件供我这样的人参考:

FROM centos:6

RUN yum install -y openssh-server
RUN mkdir /var/run/sshd

RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key

RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config

RUN echo 'root:root' | chpasswd

CMD ["/usr/sbin/sshd", "-D"]

我的docker文件供我这样的人参考:

FROM centos:6

RUN yum install -y openssh-server
RUN mkdir /var/run/sshd

RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key

RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config

RUN echo 'root:root' | chpasswd

CMD ["/usr/sbin/sshd", "-D"]

我的docker文件供我这样的人参考:

FROM centos:6

RUN yum install -y openssh-server
RUN mkdir /var/run/sshd

RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key

RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config

RUN echo 'root:root' | chpasswd

CMD ["/usr/sbin/sshd", "-D"]

如果这不起作用,请给我回电话。我今天也遇到了同样的问题,我已经找到了一些可行的解决方案。Root对于我的用例来说不是问题,实际上Root对于我的用例来说是必需的。问题一定是tutum.co,因为它在本地工作。好的,我今天晚些时候再给你回复!密码的长度可能有问题。这是一个服务器错误。它并不广为人知,但也有一些人遇到过。您能否尝试在
ssh\u config
中设置
密码aes128 ctr、aes192 ctr、aes256 ctr、arcfour256、arcfour128、aes128 cbc、3des cbc
,并告诉我它是否有效。基本上,我们的想法是通过排除使用较长密码的选项来减少密码长度。如果这不起作用,请与我联系。我今天也遇到了同样的问题,我已经找到了一些可行的解决方案。Root对于我的用例来说不是问题,实际上Root对于我的用例来说是必需的。问题一定是tutum.co,因为它在本地工作。好的,我今天晚些时候再给你回复!有