Created
June 21, 2014 17:09
-
-
Save comuttun/38497c04260529e9e266 to your computer and use it in GitHub Desktop.
Docker で SSH 接続可能なコンテナ (CentOS) を作成する ref: http://qiita.com/comutt/items/1251cc19885947cd6d3d
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| alias ssh-ignorekey='ssh -oUserKnownHostsFile=/dev/null -oStrictHostKeyChecking=no' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM centos | |
| RUN yum -y install initscripts MAKEDEV | |
| RUN yum check | |
| RUN yum -y update | |
| RUN yum -y install openssh-server | |
| # 空パスワードの場合は以下をコメントアウト | |
| # RUN sed -ri 's/^#PermitEmptyPasswords no/PermitEmptyPasswords yes/' /etc/ssh/sshd_config | |
| RUN sed -ri 's/^#PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config | |
| RUN sed -ri 's/^UsePAM yes/UsePAM no/' /etc/ssh/sshd_config | |
| RUN /etc/init.d/sshd start | |
| # 空パスワードの場合は以下をコメントアウト | |
| # RUN passwd -d root | |
| # 任意のパスワードの場合は以下をコメントアウト & パスワードを書き換える | |
| # RUN echo 'root:root' | chpasswd | |
| EXPOSE 22 | |
| CMD /sbin/init |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CONTAINER_ID=$(docker run -P -d ssh-enabled) && SSH_PORT=$(docker port $CONTAINER_ID 22 | cut -d: -f2) && SSH_HOST=$(docker port $CONTAINER_ID 22 | cut -d: -f1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ssh-ignorekey -p $SSH_PORT root@$SSH_HOST |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM centos | |
| RUN yum -y install initscripts MAKEDEV | |
| RUN yum check | |
| RUN yum -y update | |
| RUN yum -y install openssh-server | |
| RUN sed -ri 's/^#PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config | |
| RUN sed -ri 's/^UsePAM yes/UsePAM no/' /etc/ssh/sshd_config | |
| RUN /etc/init.d/sshd start | |
| RUN sed -ri 's/^(root):[^:]*:(.*)$/\1:*:\2/' /etc/shadow | |
| RUN ssh-keygen -f ~root/.ssh/id_rsa -t rsa -b 2048 -N '' | |
| RUN cp ~root/.ssh/id_rsa.pub ~root/.ssh/authorized_keys | |
| RUN chmod 0600 ~root/.ssh/authorized_keys | |
| EXPOSE 22 | |
| CMD /sbin/init |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CONTAINER_ID=$(docker run -P -d ssh-enabled) && SSH_PORT=$(docker port $CONTAINER_ID 22 | cut -d: -f2) && SSH_HOST=$(docker port $CONTAINER_ID 22 | cut -d: -f1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| docker cp $CONTAINER_ID:/root/.ssh/id_rsa $CONTAINER_ID |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ssh-ignorekey -i $CONTAINER_ID/id_rsa -p $SSH_PORT root@$SSH_HOST |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment