AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1420660
Accepted
ClonedOne
ClonedOne
Asked: 2019-04-03 17:19:28 +0800 CST2019-04-03 17:19:28 +0800 CST 2019-04-03 17:19:28 +0800 CST

Docker 容器 ssh 错误:ssh_exchange_identification: Connection closed by remote host

  • 772

我正在尝试设置一个 Ubuntu 容器,openssh-server这样我就可以从主机 ssh 进入它。我知道这不是标准的做法,但我真的很想拥有ssh.

这是我的Dockerfile

# Select base image
FROM ubuntu:16.04

# Set the current working directory
WORKDIR /home

# Update the system, download any packages essential for the project
RUN dpkg --add-architecture i386
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y git build-essential make gcc vim net-tools iputils-ping ca-certificates openssh-server libc6:i386 libstdc++6:i386

# Allow ssh root login
RUN echo "root:root" | chpasswd

# RUN rpl "PermitRootLogin prohibit-password" "PermitRootLogin yes" /etc/ssh/sshd_config
RUN sed -i 's/prohibit-password/yes/' /etc/ssh/sshd_config

RUN cat /etc/ssh/sshd_config
RUN mkdir /root/.ssh

RUN chown -R root:root /root/.ssh;chmod -R 700 /root/.ssh

RUN echo “StrictHostKeyChecking=no” >> /etc/ssh/ssh_config

RUN service ssh restart


# Open port 22 so linked containers can see it
EXPOSE 22

# Import any additional files into the environment (from the host)
ADD otherfile .

我启动容器,docker run -t -d -p 2222:22但每当我尝试 ssh 进入它时,我总是会收到错误ssh_exchange_identification: Connection closed by remote host:

➜ ssh -v -p 2222 root@localhost /bin/bash
OpenSSH_7.9p1, LibreSSL 2.7.3
debug1: Reading configuration data /Users/giorgio/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: /etc/ssh/ssh_config line 52: Applying options for *
debug1: Connecting to localhost port 2222.
debug1: Connection established.
debug1: identity file /Users/giorgio/.ssh/id_rsa type -1
debug1: identity file /Users/giorgio/.ssh/id_rsa-cert type -1
debug1: identity file /Users/giorgio/.ssh/id_dsa type -1
debug1: identity file /Users/giorgio/.ssh/id_dsa-cert type -1
debug1: identity file /Users/giorgio/.ssh/id_ecdsa type -1
debug1: identity file /Users/giorgio/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/giorgio/.ssh/id_ed25519 type -1
debug1: identity file /Users/giorgio/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/giorgio/.ssh/id_xmss type -1
debug1: identity file /Users/giorgio/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
ssh_exchange_identification: Connection closed by remote host

有谁知道导致此错误的原因以及如何解决?

ssh linux ubuntu
  • 1 1 个回答
  • 8365 Views

1 个回答

  • Voted
  1. Best Answer
    Zeitounator
    2019-04-03T18:24:06+08:002019-04-03T18:24:06+08:00

    RUN service ssh restart

    这会在映像创建阶段运行 ssh 服务重启(实际上是启动),而不是在未来运行的容器中。你里面没有CMDnor所以它默认为你的基本图像中配置的那个(它是 bash)ENTRYPOINTDockerfile

    换句话说,启动容器时没有运行 ssh 守护进程。一个临时的解决方案是在正在运行的容器上启动一个 exec 命令:docker exec your_container_name service ssh start

    要正确解决此问题,您需要指示映像在创建容器时启动 sshd(请参阅 docker 文档中的dockerize an ssh 服务)。简而言之:

    • 删除RUN service ssh restart线
    • 添加下两行
    RUN mkdir /var/run/sshd
    CMD ['/usr/sbin/sshd', '-D']
    
    • 重建你的形象,启动一个新的容器,ssh 并享受。
    • 4

相关问题

  • 需要 LDAP 身份验证 * 和 * ssh 身份验证

  • 加载密钥“ec256.pem”:尝试从私钥生成公钥时抛出无效格式

  • 如何在域和 Linux 活动目录中启用指纹传感器

  • 如何在CentOS 7 中将Ctrl+C 永久更改为Ctrl+K?

  • 为什么 chown 600 id_rsa 修复权限问题?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    Windows 10 服务称为 AarSvc_70f961。它是什么,我该如何禁用它?

    • 2 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Marko Smith

    ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] 证书验证失败:无法获取本地颁发者证书 (_ssl.c:1056)

    • 4 个回答
  • Marko Smith

    我如何知道 Windows 安装在哪个驱动器上?

    • 6 个回答
  • Martin Hope
    Albin 支持结束后如何激活 WindowsXP? 2019-11-18 03:50:17 +0800 CST
  • Martin Hope
    fixer1234 “HTTPS Everywhere”仍然相关吗? 2019-10-27 18:06:25 +0800 CST
  • Martin Hope
    Kagaratsch Windows 10 删除大量小文件的速度非常慢。有什么办法可以加快速度吗? 2019-09-23 06:05:43 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    Inter Sys Ctrl+C 和 Ctrl+V 是如何工作的? 2019-05-15 02:51:21 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve