読者です 読者をやめる 読者になる 読者になる

AKAI TSUKI

System development or Technical something

Use docker container for ssh test.

https://hub.docker.com/r/jdeathe/centos-ssh/

[root@localhost ~]# docker run -d \
>   --name ssh.pool-1.1.1 \
>   -p 2020:22 \
>   jdeathe/centos-ssh:centos-7
Unable to find image 'jdeathe/centos-ssh:centos-7' locally
centos-7: Pulling from jdeathe/centos-ssh
45a2e645736c: Already exists
c0584d31d0c7: Pull complete
312baf228c08: Pull complete
1a49aeb1a2d6: Pull complete
c94e1784cd5f: Pull complete
8f0d8715c20d: Pull complete
3ad9eac7cf9a: Pull complete
f0808ae00a9e: Pull complete
d2342971ceac: Pull complete
8b1c26542222: Pull complete
441ff7da597d: Pull complete
a6b9b592ad30: Pull complete
f1e027d49efe: Pull complete
Digest: sha256:f78be125637532943583ed4d28a1a1646db882a0f33bfa9c116de1ab1e6ee211
Status: Downloaded newer image for jdeathe/centos-ssh:centos-7
1a0afe299c430404697d6b7c4030b221083089dd77e2325e1f0f5c59031b5537
[root@localhost ~]#
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                         COMMAND                  CREATED             STATUS              PORTS                  NAMES
1a0afe299c43        jdeathe/centos-ssh:centos-7   "/usr/bin/supervisord"   24 seconds ago      Up 22 seconds       0.0.0.0:2020->22/tcp   ssh.pool-1.1.1
febbb71e5f22        centos:7                      "tail -f /dev/null"      2 weeks ago         Up About an hour                           demo
[root@localhost ~]#

To check infomation(password)

[root@localhost ~]# docker logs ssh.pool-1.1.1

and I get the insecure private key.

[root@localhost ~]# curl -LSs \
>   https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant \
>   > id_rsa_insecure
[root@localhost ~]# chmod 600 id_rsa_insecure
[root@localhost ~]#

then, I can connect to container by ssh.

[root@localhost ~]# ssh -p 2020 -i id_rsa_insecure \
>   app-admin@localhost
The authenticity of host '[localhost]:2020 ([::1]:2020)' can't be established.
ECDSA key fingerprint is a2:9e:09:54:56:d2:6c:37:69:40:6d:fa:8c:d8:64:e3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:2020' (ECDSA) to the list of known hosts.
[app-admin@1a0afe299c43 ~]$ ls -l
total 0
[app-admin@1a0afe299c43 ~]$

and directly,

[root@localhost ~]# docker inspect 1a0afe299c43 |grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.3",
                    "IPAddress": "172.17.0.3",
[root@localhost ~]# ssh -i id_rsa_insecure app-admin@172.17.0.3
The authenticity of host '172.17.0.3 (172.17.0.3)' can't be established.
ECDSA key fingerprint is a2:9e:09:54:56:d2:6c:37:69:40:6d:fa:8c:d8:64:e3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.17.0.3' (ECDSA) to the list of known hosts.
Last login: Sun Jan 15 17:24:23 2017 from 172.17.0.1
[app-admin@1a0afe299c43 ~]$