Containerized SSH Server
SAKSHAM TRIVEDI
Security (SOC) Analyst || Microsoft Certified Security Operation Canter Analyst
In this article I am going to demonstrate how to containerize SSH server so without any further explanation let's directly jump to terminal.
Whoa whoa whoa... wait, hold your excitement right here, since I mentioned container already in the article's tittle, which means you need to have at least basic understanding of Docker and how to install it and few docker commands.
Prerequisite:
Docker installed on your system.
Internet Connection
Basic Knowledge in docker commands
That's It.
So now,
Our Workbench:
Before heading towards anything we need a workbench so first things first... let's bring up our workbench by creating a directory using the command.
$ mkdir ssh-server && cd ssh-server/ && pwd
Now our directory is workbench (If you pulled out your wooden workbench from the store room then put back there we don't need it.)
Now to verify that our directory is created and you're inside the directory you can look at the output after typing the command as shown in below image
Once, you have done with creating a directory we'll now up our game by creating a file called Dockerfile inside the directory using any of the text editor you like, In my case it's vim.
$ vi Dockerfile
and then append the below lines in the Dokcerfile
FROM ubuntu:latest
RUN apt update -y && apt install -y openssh-server
EXPOSE 22
RUN service ssh start
CMD ["/usr/sbin/sshd", "-D"]
Just like the below I image:
and save the file:
If using vim press ESC then press :wq to save the content into the file and quit vim editor.
We have defined our image and it's time to build our image using Docker command
领英推荐
$ sudo docker build -t ssh-server .
If you see the output like below it means your image has started building.
There's a lot going on with under the hood and if you want to know then keep update with my blog posts, I will be adding complete docker series for beginners where I will be explaining about major aspects of Docker and breakdown of commands.
Wait for a while to download all the dependencies and build your image. once the image is built successfully you will see this output or similar
The image is cached into your local system, but the actual container is not deployed yet. So, in order to deploy the container, you need to enter the following command to deploy the container image and run in a detached mode (using -d)
$ sudo docker run -d ssh-server
Congratulations... Your ssh-server inside the container is up and running. To verify the connectivity first check your ssh deamon is running or not by typing,
$ systemctl status sshd
If you see output like above it means ssh is disable for your system. so to enable the ssh deamon type the below commands and hit enter
Now, to connect with the SSH server use below command
Type 'yes' and press Enter.
You're now inside the docker container running an ssh-server to verify type
$ pwd
You will see that your home directory is not visible, Instead, home directory for root will be printed.
Now you can start working on whatever you like.
That's it for now... I will be back soon with next article
Till then checkout my other blogs post and visit my linked profile to reach out.
Thanks
- SK -