Skip to content

Latest commit

 

History

History
90 lines (66 loc) · 2.24 KB

File metadata and controls

90 lines (66 loc) · 2.24 KB

README

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

Architecture

graph LR
    subgraph host
        A(client)
    end
    subgraph docker
        A(client) -->|ssh| B(sshserver)
        B -->|curl| C(internalnginx)
    end

Loading

Run example

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

🧼 Cleanup

# bring it down and delete the volume
docker compose down 

Debugging and troubleshooting

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

👀 Resources

  • marcelloromani/dockerfiles repo
  • What causes SSH error: kex_exchange_identification: Connection closed by remote host? here
  • Enable ed25519 SSH Keys Auth on Ubuntu 18.04 here
  • Mermaid docs here