Make a docker container with Red Hat and ssh into it
Docker is an open platform for developing, shipping and running application. You will be able have an isolated environment on your local machine with a bit resources you use.
Someone use docker to run their vulnerable application because of docker have isolation and good for making penetration testing lab. So today I wanna to make a sshd services run in the docker.
Learn more about docker here.
Pull the Image
All docker images are provided in hub.docker.com. You can choose your favorite image as your base of running the docker container. For this tutorial I will use Red Hat UBI 8.
For safety tips, I recommend you to always pull an image from Verified Publisher.
First of all, you must install docker on your computer/ your VM.
And then just run the command below.
docker pull redhat/ubi8pulling docker image
If it has been finished, run this command for looking the list of images
docker image ls
If your docker image ls command shows like the picture above, congratulation you have been pulling the image and save on your computer.
Run a container
In Docker, the command “run” means create and start your container.
docker run -it –name ssh-test -p 10022:22 fca12da1dc30
-it : run with interactive shell of container
–name ssh-test : the name of the container is ssh-test
-p 10022:22 : port 10022 in local machine and port 22 in docker container
fca12da1dc30 : the IMAGE ID.
Once you run the container, it will spawn an interactive shell with the random hostname:
Run update package repository,
and install openssh-server,
usr/bin/yum install openssh-server
And then, Generate the host keys with:
And the last step, start the ssh server, run /usr/sbin/sshd &.
Before testing, I wanna make new user as jarvis.
useradd –home /home/jarvis jarvis
Open new tab and access the ssh.
How about access from virtual machine?
Try to ssh into your host machine (which is your docker running) with username jarvis and port 10022. But, make sure that your VM and your host machine have bridge connection.
ssh to docker from windows virtual machine
Actually docker provides you a direct connection to your docker container. If you run sshd, it will make your docker not isolate again.
But if you wanna learn about any OS, docker is a better way than virtual machine because that container just needs a bit of your resources (ram/storage).