Containerized SSH Server

Containerized SSH Server

In this article I am going to demonstrate how to containerize SSH server so without any further explanation let's directly jump to terminal.

No alt text provided for this image
Excited!!!

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,

No alt text provided for this image
@tenor

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

No alt text provided for this image
Workbench

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:

No alt text provided for this image
Dockerfile

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.

No alt text provided for this image
Building Image

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

No alt text provided for this image
Image built successfully

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        
No alt text provided for this image
sshd status

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

No alt text provided for this image
ssh staus (up and running)

Now, to connect with the SSH server use below command

No alt text provided for this image
connecting to SSH server

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.

No alt text provided for this image
ssh-server container

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 -

要查看或添加评论,请登录

SAKSHAM TRIVEDI的更多文章

  • DNF5... It's time to rethink the package management.

    DNF5... It's time to rethink the package management.

    Hello Folks, It's been a while since I have written any article. Well here I am now.

  • File BackuP & Sync...

    File BackuP & Sync...

    Introduction In today's fast-paced world, seamless file sharing and synchronization are essential for efficient…

  • Simplifying SSH Connection: A Guide To Build Your Own Proxy Network

    Simplifying SSH Connection: A Guide To Build Your Own Proxy Network

    Establishing a secure SSH connection between Machine A and Machine F can be challenging, especially when intermediate…

  • Unleashing the Power of Linux: A Browser-Based Linux Experience

    Unleashing the Power of Linux: A Browser-Based Linux Experience

    To access Fedora Linux's graphical system in a browser using Apache Guacamole, you will need to set up Guacamole on a…

  • Gmail from Old Dog Terminal

    Gmail from Old Dog Terminal

    Mutt is used to send and receive email from your terminal, even if you're using hosted service such as Gmail. A…

  • Let's WhatsApp using Bash

    Let's WhatsApp using Bash

    S: AuthorAuthorIntroduction In today's fast-paced world, automation plays a crucial role in streamlining various tasks.…

    5 条评论
  • Ping... a message arrrived

    Ping... a message arrrived

    In this short tutorial, Here I am going to demonstrate chatting using ping command. For this first of all you need a…

    1 条评论
  • Mutiple Linux shells on a same system

    Mutiple Linux shells on a same system

    Recently I came across the question is there any possibility that multiple shells can be installed on the same system…

  • Jupyter Lab as a container

    Jupyter Lab as a container

    This article is focused on containerizing Jupyter Notebook inside the docker container with a fully-fledged develop…

  • Launching graphical application inside the docker container

    Launching graphical application inside the docker container

    Hello guys, In this article I am going to discuss how to launch the graphical application inside the docker. So, for…

社区洞察

其他会员也浏览了