I created a docker image which is subjected to test to login into container with SSH. However when I try to ssh into the container, I was asked the root password. Any ideas to get around it.
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
SSH user authentication by password is enabled by default, with the username/password being “anonymous”.
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 fallback to username/password authentication.
An example would be "Setting ssh public keys on Docker image", but I don't like it as it means the container has the private key (it does not need it)
It is best to:
COPY yourPublicKey /root/.ssh/authorized_keys
in your DockerfileThat generates an image whose containers will be able to be accessed by ssh.
Make sure that, on your host, your $HOME/.ssh
does have the private key id_rsa
and public key id_rsa.pub
.
That enables ssh authentication between your docker host and your docker container, following the general (ie., not specific to docker) ssh authentication mechanism shown here:
(source "GitHub public key authentication", from Sébastien Saunier - @ssaunier)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With