本文介绍了无法通过 ssh 进入 Azure 应用服务上的 linux 容器 - “SSH CONNECTION CLOSE - 错误:连接 ECONNREFUSED"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 ssh 连接到 Azure 应用服务的容器.我已按照此处的说明配置我的容器:

I'm trying to ssh into a container for Azure app service. I have followed the instructions for configuring my container here:

https://docs.microsoft.com/en-gb/azure/app-service/containers/configure-custom-container#enable-ssh

以及在此处连接的说明:

and the instructions to connect here:

https://docs.microsoft.com/en-gb/azure/app-service/containers/app-service-linux-ssh-support

以下是我的 docker 文件中的相关步骤:

Here are the relevant steps in my docker file:

RUN apt-get update \
     && apt-get install -y --no-install-recommends dialog \
     && apt-get update \
     && apt-get install -y --no-install-recommends openssh-server \
     && echo "root:Docker!" | chpasswd

EXPOSE 8000 2222

COPY sshd_config /etc/ssh/

CMD ./bin/start.sh

start.sh 启动的地方运行服务 ssh start.sshd_config 文件是

where start.sh starts runs service ssh start. The sshd_config file is

# This is ssh server systemwide configuration file.
#
# /etc/sshd_config

Port            2222
ListenAddress       0.0.0.0
LoginGraceTime      180
X11Forwarding       yes
Ciphers aes128-cbc,3des-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr
MACs hmac-sha1,hmac-sha1-96
StrictModes         yes
SyslogFacility      DAEMON
PasswordAuthentication  yes
PermitEmptyPasswords    no
PermitRootLogin     yes
Subsystem sftp internal-sftp

当我尝试从门户通过 ssh 连接时,它首先显示 "CONNECTED | CREDENTIALS" 然后在 30 秒左右后显示 "SSH CONNECTION CLOSE - Error: connect ECONNREFUSED <ip>:2222"

When I try and connect by ssh from the portal it first says "CONNECTED | CREDENTIALS" then after 30 seconds or so it says "SSH CONNECTION CLOSE - Error: connect ECONNREFUSED <ip>:2222"

不确定为什么无法连接?

Not sure why this is not connecting?

推荐答案

修复我的错误的是指定了 sshd 需要的缺少运行时目录.对于 debian Linux distor,我必须创建 /run/sshd 目录.另一件重要的事情是启动 sshd 守护进程对我来说是 /usr/sbin/sshd

What fixed my error was to specified missing runtime directory that sshd requires. For debian Linux distor it I had to create /run/sshd directory. Another thing that was important is to start sshd daemon by full for me it was /usr/sbin/sshd

Dockerfile

FROM nginx:latest

RUN apt-get update && apt-get install -y ssh
RUN echo "root:Docker!" | chpasswd
RUN mkdir /run/sshd

WORKDIR /app
COPY startup.sh /app
COPY sshd_config /etc/ssh/

EXPOSE 80 2222

CMD /app/startup.sh

/app/startup.sh

#!/bin/sh

echo "Start sshd"
/usr/sbin/sshd

echo "Start nginx"
nginx -g "daemon off;"

sshd_config

Port                2222
ListenAddress       0.0.0.0
LoginGraceTime      180
X11Forwarding       yes
Ciphers aes128-cbc,3des-cbc,aes256-cbc,aes128-ctr,aes192-ctr,aes256-ctr
MACs hmac-sha1,hmac-sha1-96
StrictModes         yes
SyslogFacility      DAEMON
PasswordAuthentication  yes
PermitEmptyPasswords    no
PermitRootLogin         yes
Subsystem sftp internal-sftp

要验证您是否可以通过 ssh 进入容器,请运行此命令

To verify that you can ssh into container run this command

# Password: Docker!
$ ssh root@IP_OF_CONTAINER -p 2222

# Debug
ssh [email protected] -p 2222 -vvvv

这篇关于无法通过 ssh 进入 Azure 应用服务上的 linux 容器 - “SSH CONNECTION CLOSE - 错误:连接 ECONNREFUSED"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 22:39