Forum Navigation
You need to log in to create posts and topics.

Create SSH Docker – Ubuntu latest

Problem

User wants to create an SSH docker for tests

Solution

Create a file called Dockerfile in the directory for the build (or download the docker file ) and copy this contents

FROM ubuntu:latest
RUN apt update && apt install openssh-server sudo -y
RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u 1000 test
RUN echo ‘test:test’ | chpasswd
RUN service ssh start
RUN mkdir -p /usr/local/tracston
EXPOSE 22
CMD [“/usr/sbin/sshd”,”-D”]

Build the Docker

sudo docker build -t SSHcontainer -f Dockerfile .

Run the Docker

sudo docker run -d -p 2222:22 SSHcontainer

Test

ssh test@localhost -p 2222

Notes

the port exposd for the docker during docker run is 2222

Change the default user: test, password: test in the Docker file

Forum changes the backticks and apostrophes which is not compatible to the shell commands. please download dockerfile or change

Uploaded files:

if you get error Exiting 127  add the following ssh commands

RUN sudo apt-get install ssh

RUN sudo systemctl ssh start

RUN sudo systemctl ssh enable

RUN service ssh status

If you have found my website, guides, articles or videos useful, please buy me a coffee