My problem is almost exactly the same as the following link, except my ssh server is in a docker container.
My Dockerfile is very simple.
FROM ubuntu:12.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get install -y openssh-server less nano
RUN mkdir /var/run/sshd
RUN adduser chrome
RUN echo "chrome:chrome" | chpasswd
RUN echo "root:chrome" | chpasswd
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
When I try to ssh login, it hangs forever starting the shell.
$ ssh -p2222 chrome@localhost /bin/bash --noprofile --norc # trying to login with ssh
chrome@localhost's password: <-------------hangs forever
I can login if I use the -t
argument on ssh. I don't know why.
Running other programs like ls
works without problems. Perhaps someone can replicate this container and figure out what the problem is?
This is nothing to do with docker, you can get the same thing to happen when you ssh to a remote host.
A clue to the problem is in the ssh man page
So, ssh doesn't use a tty allocation if you provide a remote command to be run unless you use the
-t
switch. As bash is interactive it requires a tty.The following will not hang
The
-i
option for bash is required to get an interactive shell.From the Bash Reference Manual 1.2 What is a shell? section:
and 6.3.1 What is an Interactive Shell?:
When you start a container with
docker run
you have to specify-it
for an interactive terminal for the exact same reason as explained above.As an observation from your
dockerfile
you can add--net=host
to yourdocker run
command so that the container can access the native NIC configurations if you do not want to useEXPOSE 22
explicitly.Also, (as dumb as it sounds, I know) I have had issues at login with docker even on a local container where it appears to hang but if I just hit
<enter>
I then get the prompt...