Secure SSH Configuration in a Docker CentOS Container

Introduction:
In this blog post, we will explore how to configure SSH inside a CentOS-based Docker container and establish secure communication between the container and the host system. By following these steps, you can securely log in to the host system from inside the container and vice versa, allowing for seamless interaction between the two environments.
Step 1: Install Docker in your local machine. Now run one container using centos:7 image
yum install docker && systemctl start docker

Step 2: Now install both ssh server and ssh client in the same docker container. Use below commands.
yum install openssh-server
yum install openssh-clients
Configure ssh. open /etc/ssh/sshd_config and remove # to the below line.

Before starting ssh service, you have to generate some required keys by server using below command
ssh-keygen -A
Step 3: Start the ssh services
/usr/sbin/sshd
Now try ssh to ur host machine. In my case it is redhat system

Its working fine. Let’s try ssh from host system to docker OS. For this, first you have to know the docker IP. Here is the command

Now I’m going to do ssh to 172.17.0.2 Docker IP. Will it work ?

As you see, it says permission denied. Why because, we haven’t given password to the root account in docker OS. To give password use below command. Run the below cmd inside docker OS.
echo ‘root:redhat’ | chpasswd
Now try again to do ssh to docker OS.

Conclusion:
By following the steps outlined in this blog post, you can configure SSH inside a Docker CentOS container and establish a secure connection between the container and the host system. This setup allows for seamless interaction and secure remote management of the containerized environment. With proper security configurations in place, you can confidently utilize SSH for various administrative tasks and development workflows within your Docker environment.
…Signing Off…