Password requested when ssh to container

I created a docker image that is being tested to enter a container with SSH. However, when I try to enter the container, I was given the root password. Any ideas to get around this.

Dockerfile

FROM ubuntu:trusty

RUN apt-get update

RUN apt-get install -y openssh-server supervisor vim build-essential git
RUN mkdir -p /var/run/sshd
ADD supervisord/sshd.conf /etc/supervisor/conf.d/sshd.conf
RUN echo 'root:root' | chpasswd

EXPOSE 22
CMD ["/usr/bin/supervisord"]

supervisord / sshd.conf

[supervisord]
nodaemon=true

[program:sshd]
command=/usr/sbin/sshd -D
+4
source share
1 answer

You need to add your public key to the container root/.ssh/authorized_keys

If sshd does not find your public key there, it will refuse authentication of the username and password.

An example would be " Installing ssh public keys on a Docker image ", but I do not like it, since this means that the container has a private key (it does not need to)

The best thing:

  • / .
  • COPY yourPublicKey /root/.ssh/authorized_keys Docker

, ssh.

, $HOME/.ssh id_rsa id_rsa.pub.

ssh - , ssh (.. ):

http://sebastien.saunier.me/images/posts/SSH%20Connection%20explained.png

( " GitHub", - @ssaunier)

+5

All Articles