Demonstrate how to use ssh inside a docker container
Creates a container running sshd that allows access to the nginx container on the same network.
ℹ️ NOTE: This is root only login
graph LR
subgraph host
A(client)
end
subgraph docker
A(client) -->|ssh| B(sshserver)
B -->|curl| C(internalnginx)
end
The nginx container is not available on the network. We use the ssh server to allow access.
# create keys
mkdir -p ./ssh_server/keys
ssh-keygen -o -a 100 -t ed25519 -f ./ssh_server/keys/id_ed25519
ssh-keygen -o -a 100 -t rsa -f ./ssh_server/keys/id_rsa Start the containers.
# start server
docker compose up -d --build --force-recreate
# quick test
docker compose logs internalnginx
docker compose logs sshserver SSH to get access to nginx.
# ssh onto server
ssh -vvvv -o StrictHostKeyChecking=no -i ./ssh_server/keys/id_rsa -p 2822 root@0.0.0.0
# curl against the nginx container
curl 172.16.238.64:80# bring it down and delete the volume
docker compose down docker compose exec -it sshserver /bin/bash
# start ssh
rsyslogd
service ssh start
nano /etc/ssh/sshd_config
service ssh restart
passwd
cat /root/.ssh/authorized_keys
cat /var/log/auth.log
#PasswordAuthentication yes
#PermitEmptyPasswords yes
#PermitRootLogin without-password
# open connections (only rsa seems to work)
ssh -vvvv -o StrictHostKeyChecking=no -i ./ssh_server/keys/id_ed25519 -p 2822 root@0.0.0.0
ssh -vvvv -o StrictHostKeyChecking=no -i ./ssh_server/keys/id_rsa -p 2822 root@0.0.0.0