【问题标题】:/bin/sh: /usr/sbin/sshd-keygen: No such file or directory/bin/sh: /usr/sbin/sshd-keygen: 没有那个文件或目录
【发布时间】:2020-03-29 13:58:40
【问题描述】:

我对 linux 和 docker 概念完全陌生

在我的 windows 机器上,我在虚拟机中启动 centos7

在运行 docker-compose build 时,我得到了

 /bin/sh: /usr/sbin/sshd-keygen: No such file or directory

如何改正

我尝试创建一个远程用户

docker-compose.yml

version: '3'
services:
  jenkins:
    container_name: jenkins
    image: jenkins/jenkins
    ports:
      - "8080:8080"
    volumes:
      - "$PWD/jenkins_home:/var/jenkins_home"
    networks:
      - net
  remote_host:
    container_name: remote-host
    image: remote-host
    build:
      context: centos7
    networks:
      - net
networks:
   net:
DockerFile

FROM centos

RUN yum -y install openssh-server

RUN useradd remote_user && \
    echo "Thevenus987$" | passwd remote_user --stdin && \
    mkdir /home/remote_user/.ssh && \
    chmod 700 /home/remote_user/.ssh

COPY remote-key.pub /home/remote_user/.ssh/authorized_keys

RUN chown remote_user:remote_user -R /home/remote_user/.ssh && \
    chmod 600 /home/remote_user/.ssh/authorized_keys

RUN /usr/sbin/sshd-keygen

CMD /usr/sbin/sshd -D

【问题讨论】:

标签: linux docker docker-compose centos7


【解决方案1】:

在 Dockerfile 中

更改RUN /usr/sbin/sshd-keygen // Centos8 不接受这个命令

to RUN ssh-keygen -A // 这行得通。

我希望这个解决方案能正常工作。

【讨论】:

  • 这些命令做不同的事情。 sshd-keygen 是发行版提供的用于生成主机密钥的脚本。
【解决方案2】:
  1. 将 FROM 更改为 centos:7
  2. 将 RUN /usr/sbin/sshd-keygen 替换为 RUN ssh

【讨论】:

    【解决方案3】:

    Dockerfile 应该是这样的:

    FROM centos:7
    
       RUN yum -y install openssh-server && \
        yum install -y passwd && \  #Added
        yum install -y initscripts  #Added 
    
    RUN useradd remote_user && \
      echo "1234" | passwd remote_user --stdin && \
      mkdir /home/remote_user/.ssh && \
      chmod 700 /home/remote_user/.ssh
    
    COPY remote-key.pub /home/remote_user/.ssh/authorized_keys
    
    RUN chown remote_user:remote_user -R /home/remote_user/.ssh/ && \
        chmod 600 /home/remote_user/.ssh/authorized_keys
    
    RUN /usr/sbin/sshd-keygen
    
    #CMD /usr/sbin/sshd -D
    CMD ["/usr/sbin/sshd", "-D"]
    

    【讨论】:

      【解决方案4】:

      只需使用 FROM centos:7(而不是使用 centos8 基础镜像)

      yum install -y 初始化脚本

      注意: 更新的 initscripts 错误修复增强包修复了几个错误并添加了一项增强功能,现在可用于 Red Hat Enterprise Linux 6/7。

      您根本不需要删除或调整以下行

      运行 /usr/sbin/sshd-keygen

      它将工作 100% ..

      要了解有关 initscripts 错误修复增强功能的更多信息: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/6.5_technical_notes/initscripts

      【讨论】:

        【解决方案5】:

        把基础镜像FROM centos改成FROM centos:7就可以了

        【讨论】:

          【解决方案6】:

          问题在于 Dockerfile 中的这一行:

          RUN /usr/sbin/sshd-keygen

          这是执行此行时得到的结果: /etc/rc.d/init.d/functions: 没有这样的文件或目录。 /usr/sbin/sshd-keygen: 找不到命令。

          这个 init.d/functions 文件对于不同的 Linux 发行版是不同的。它特定于您正在运行的任何发行版。该文件包含存储在 /etc/init.d 中的大多数或所有 shell 脚本使用的函数。 d 目录。

          要亲自尝试,只需从 docker hub 拉取 CentOS:7 映像,然后从 Dockerfile 测试 RUN 步骤,如下所示:

          docker container run -i -t -d --name test centos:7

          docker exec -it test bash

          cd /etc/rc.d/init.d

          ls -a

          此目录中没有调用函数的文件。

          在 CentOS:7 Docker 映像中,您必须简单地安装包 initscripts 才能安装此脚本,因此将这些行添加到您的 Dockerfile:

          FROM centos:7

          RUN yum install -y initscripts

          【讨论】:

            【解决方案7】:

            FROM centos 默认拉取最新的,不包括 sshd-keygen。

            您需要将 Dockerfile 更改为:

            FROM centos:7
              ...
                && yum install -y initscripts \
                && /usr/sbin/sshd-keygen
            
            CMD ["/usr/sbin/sshd", "-D"]
            

            【讨论】:

              【解决方案8】:

              只需从 centos 更改 FROM centos:7

              出现这个错误是因为之前 docker centos 运行 centos7,现在运行 centos 8

              【讨论】:

                【解决方案9】:

                试试下面的命令而不是RUN /usr/sbin/sshd-keygen 并且正如其他人指出的那样使用: FROM centos:7

                RUN ssh-keygen -A

                【讨论】:

                • 嗨 Ankit。欢迎!感谢您为 Stack Overflow 做出贡献。我对这个答案投了反对票,因为它与这个问题的现有答案相同。请考虑删除它。
                【解决方案10】:

                1) 在 Dockerfile 中更改:

                RUN /usr/sbin/sshd-keygen
                

                RUN /usr/bin/ssh-keygen
                

                2) 或尝试

                RUN sshd-keygen
                

                如果它包含并存在于您的 $PATH 中的任何位置,它将执行。

                【讨论】:

                猜你喜欢
                • 2021-04-22
                • 2023-04-09
                • 2021-03-09
                • 1970-01-01
                • 2019-12-10
                • 2015-11-24
                • 2023-02-06
                • 2023-03-05
                • 1970-01-01
                相关资源
                最近更新 更多