Steps To Use SSH Keys Inside Docker Container
Step 1: Run an Ubuntu docker container using the below command.
docker run -it -d -p 2200:22 --name ssh-access-server ubuntu:latest
Step 2 : Go inside the docker container .
docker exec -it ssh-access-server bash
Step 3 : Use the commands below to install openssh-server and nano on the Ubuntu docker container .
apt update
apt install openssh-server -y
apt install nano -y
Step 4 : Edit the sshd_config file . Here make the PermitRootLogin to yes .
nano /etc/ssh/sshd_config
Then search for PermitRootLogin and make it yes .
Step 5 : Then start the SSH service on Ubuntu docker container .
service ssh start
You can use this command below to check the status of SSH .
service ssh status
Step 6 : Now change the password of the Ubuntu docker container .
passwd
Step 7 : Now open another terminal on your host and write this command to access the Ubuntu docker container through SSH . Then you have to give the password you have set for Ubuntu docker container .
ssh root@localhost -p 2200
Now you have successfully accessed the Ubuntu docker container through SSH .
How To Use SSH Keys Inside Docker Container?
SSH key is a credential used for remote access of servers without using any type of username and password and Docker is a containerization tool used to encapsulate the application with its dependencies into compact units called docker containers. In this guide, I will first discuss what is SSH key and how it works. Then I will discuss docker. After that, I will walk you through the different steps to use SSH keys inside a docker container.