ssh Connection reset by 192.168.x.x
The first thing to try is increase the verbosity of ssh
by adding -v
:
ssh -v moutend@`docker-machine ip dev` -p 32772
that will give you extra debugging information.
If that doesn't help, and assuming you used docker run --name sshtest -d -P test
to name the container sshtest
;
docker logs sshtest
to see if sshd
is (still) running. (This will show that the /etc/ssh/ssh_host_ed25519_key
host ssh keys are missing, and you have to run ssh-keygen -A
once to generate those host keys in /etc/ssh/
)
If it were still running you can check the setup
of the inside for correctness by exec
-ing into the the container:
docker exec -it sshtest /bin/bash
Of course using docker exec
eliminates the need for running sshd
in a lot of containers in the first place.
You can also look at what others have done in similar setups (if you haven't already e.g. this setup
Related videos on Youtube
moutend
Updated on September 18, 2022Comments
-
moutend over 1 year
I'm trying to ssh login from Mac OSX 10.10 into CentOS 7.1 on boot2docker by using public key authentication. The problem is that ssh shows
Connection reset by 192.168.99.100
when I login to CentOs (192.168.99.100 is the container's IP address). Here is my Dockerfile for building CentOS image:FROM centos:centos7 MAINTAINER moutend <[email protected]> RUN yum -y update; yum clean all RUN yum -y install openssh-server RUN mkdir /var/run/sshd RUN sed -i 's/^#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config RUN sed -i 's/^PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config ADD id_ecdsa.pub /home/moutend/.ssh/authorized_keys RUN adduser -g wheel moutend RUN echo moutend:foobarfoobar | chpasswd RUN chown -R moutend:wheel /home/moutend RUN chmod 600 /home/moutend/.ssh/authorized_keys EXPOSE 22 CMD ["/usr/sbin/sshd", "-D"]
The following commands are I did.
# On Mac OSX ssh-keygen -t ecdsa docker-machine create -d virtualbox dev docker-machine scp myDockerfile id_ecdsa.pub dev: docker-machine ssh dev # Login to boot2docker # On boot2docker docker build -t test -f myDockerfile . docker run -d -P test docker port `docker ps -lq` # Get the port for ssh
And then I got the error message below:
ssh-add id_ecdsa ssh moutend@`docker-machine ip dev` -p 32772 Connection reset by 192.168.99.100
Ofcourse the port number is correct. So I don't know why connection reset happens. How can I solve this?
-
Jakuje over 8 yearsmake sure that also
~/.ssh
directory has proper permissions. Running the server in debug mode (-ddd
) might also give some clue. -
moutend over 8 years@Jakuje Thanks. However
~/.ssh
directory is mode 700. It's proper permission.
-
-
moutend over 8 years
docker logs
showsCould not load host key: /etc/ssh/ssh_host_ed25519_key
. So I putRUN ssh-keygen -A
into my Dockerfile, everything works fine and I can login to the container by using public key authentication. Thank you for giving me many advices! -
Anthon over 8 years@moutend I updated my answer with that info (so future visitors don't have to read all the way down to the comments). Consider accepting my answer (clicking the V next to it) if it solves your problem, that is the way people seeing your question on this site, know it has a working answer.