centos:
mkdir centos-ssh
vim centos-ssh/Dockerfile
FROM centos
MAINTAINER blog.rootr.cn [email protected]
RUN yum install -y openssh-server
RUN mkdir /var/run/sshd
RUN ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ‘‘ && \
ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ‘‘ && \
ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N ‘‘
RUN echo "root:1234" | chpasswd
ENTRYPOINT ["/usr/sbin/sshd","-D"]
EXPOSE 22
docker build -t centos:ssh /root/centos-ssh/
docker run -d -p 2222:22 centos:ssh
ssh [email protected] -p 2222
Are you sure you want to continue connecting (yes/no)? yes
[email protected]‘s password: 1234
[[email protected] ~]#
ubuntu:
mkdir ubuntu-ssh
vim ubuntu-ssh/Dockerfile
FROM ubuntu
MAINTAINER blog.rootr.cn [email protected]
RUN apt-get update -y
RUN apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo "root:1234" | chpasswd
#允许root用户以任何认证方式登陆(用户密码认证和公钥认证)
RUN sed -i ‘s/prohibit-password/yes/g‘ /etc/ssh/sshd_config
ENTRYPOINT ["/usr/sbin/sshd","-D"]
EXPOSE 22
docker build -t ubuntu:ssh /root/ubuntu-ssh/
docker run -d -p 2223:22 ubuntu:ssh
ssh [email protected] -p 2223
Are you sure you want to continue connecting (yes/no)? yes
[email protected]‘s password: 1234