1

A little preamble: some CICD integration tests need to be able to connect via ssh to a user with a suite of test files in its home directory. This is the Dockerfile I wrote to create that:

FROM alpine:latest
WORKDIR /src
COPY ./src /src
RUN apk update
RUN apk add bash
RUN apk add openssh
RUN apk add openrc
RUN rc-update add sshd 
RUN adduser -g "" -D testuser
RUN echo testuser:testpassword | chpasswd
EXPOSE 22 

That builds an image that I then mount interactively to stop it from immediately exiting.

docker run -dit --rm -p 5022:22 6dbd5f8ae874

At this point I was expecting to be able to connect:

ssh testuser@localhost -p 5022

but ssh says

kex_exchange_identification: Connection closed by remote host
Connection closed by 127.0.0.1 port 5022

Remembering that the context for this is Alpine Linux as at 2022-07-06:

  • Which needs changing - client, server or both?
  • How and where?
Peter Wone
  • 121
  • 1
  • 1
  • 6

2 Answers2

0
RUN echo -n 'PasswordAuthentication yes' >> /etc/ssh/sshd_config

allows password authentication and the error stops appearing. Further configuration will be required to support key based authentication at which point password auth could be retired. In the meantime it works.

Peter Wone
  • 121
  • 1
  • 1
  • 6
0

You are installing packages, but you are not starting anything. SSHd is just not running.

If you take the alpine-openrc project as an example, add this to your Dockerfile:

CMD ["/sbin/init"]

Or, if you notice the deprecation warning on that project:

Please use *-openrc branches of dockage/alpine instead of this project.

So, you could just use:

FROM dockage/alpine:3.11-openrc
Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89