Search code examples
dockersshopensshtty

How to permit SSH connexion to a docker container with complete prompt?


I try to deploy debian containers to allow users to connect to them over SSH (for students for exemple).

I managed to do this but when I am connected to the container I have a pseudo-TTY and it's not the expected result I want. I want to have a complete interactive shell like when we connect to a reel server or machine.

I tried several ideas like :

  • change the docker add options in my docker run commands like : docker run -d -it CONAINER_ID

  • change the sshd_config in the debian container to allow TTY

  • change my dockerfile many times

  • add ssh options when I connect : ssh -t or ssh -tt

But any of theses ideas seems to help me. I show you my current Dockerfile it can be helpfull.

FROM debian:latest

RUN apt-get update && apt-get install -y openssh-server && apt-get install -y sudo nano 

RUN mkdir /var/run/sshd

RUN service ssh start

RUN useradd -m john && echo "john:john" | chpasswd && adduser john sudo

EXPOSE 22

CMD ["/usr/sbin/sshd", "-D"]

So can any one tell me if I can change or do something to resolve this problem please ? Thanks


Solution

  • I solved this problem with adding just one option in my Dockerfile when I create the user :

    RUN useradd -ms /bin/bash john && echo "john:john" | chpasswd && adduser john sudo
    

    Now, when I log into the container with SSH, I have a fully complete SHELL.