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

Viewed 5570

I'm completely new to linux and docker concepts

In my windows machine I boot up centos7 in virtual box

while running docker-compose build I get

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

How to rectify it

I tried to create a remote user

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

10 Answers

In Dockerfile

Change RUN /usr/sbin/sshd-keygen // Centos8 doesn't accept this command

to RUN ssh-keygen -A // This works.

I hope this solution works fine.

  1. Change the FROM as centos:7
  2. Replace RUN /usr/sbin/sshd-keygen to RUN ssh

The Dockerfile should be like this:

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

just use FROM centos:7 (instead of using centos8 base image)

and

yum install -y initscripts

Note: Updated initscripts bug fix enhancement package fixes several bugs and add one enhancement are now available for Red Hat Enterprise Linux 6/7.

you don't need to remove or twek this below line at all

RUN /usr/sbin/sshd-keygen

it will work 100% ..

To learn more about initscripts bug fix enhancement: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/6.5_technical_notes/initscripts

Change the base image FROM centos to FROM centos:7 and it will work

The problem is with this line in your Dockerfile:

RUN /usr/sbin/sshd-keygen

This is what you get when this line gets executed: /etc/rc.d/init.d/functions: No such file or directory. /usr/sbin/sshd-keygen: command not found.

This init.d/functions file is different for different linux distros. It's specific to whatever distribution you're running. This file contains functions to be used by most or all shell scripts stored in the /etc/init. d directory.

To try this yourself simply pull the CentOS:7 image from docker hub and test your RUN steps from your Dockerfile as follows:

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

docker exec -it test bash

cd /etc/rc.d/init.d

ls -a

There is no file called functions in this directory.

In CentOS:7 Docker image you have to simply install the package initscripts in order for this script to be installed, so add these lines to your Dockerfile:

FROM centos:7

RUN yum install -y initscripts

FROM centos pulls the latest by default which does not include sshd-keygen.

You need to change your Dockerfile to:

FROM centos:7
  ...
    && yum install -y initscripts \
    && /usr/sbin/sshd-keygen

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

Just change FROM centos FROM centos:7

That error happened because before docker centos run centos7 and now run centos 8

try below command instead of RUN /usr/sbin/sshd-keygen and also as others pointed out use: FROM centos:7

RUN ssh-keygen -A

1) in Dockerfile change:

RUN /usr/sbin/sshd-keygen

to

RUN /usr/bin/ssh-keygen

2) or try

RUN sshd-keygen

if that is included and exists anywhere in your $PATH, it will execute.

Related