制作可以SSH的Docker容器

以 Ubuntu 16.04为例:

 

Docker里的root密码是随机的, 用passwd来设置新的密码

 

安装完SSH_SERVER后, 默认是不能用root登录的. 

vi /etc/ssh/sshd_config
将PermitRootLogin no 改为 PermitRootLogin yes
将PasswordAuthentication no 改为PasswordAuthentication yes

然后重启SSH服务

 

docker的IP地址默认是随机的 

ip -4 -o address show 来显示IP

 

用 ssh root@docerip 来登录.

 

也可参考下面的过程, 制作SSH可登陆的镜像.

 
 
FROM       ubuntu:18.04
MAINTAINER Aleksandar Diklic "https://github.com/rastasheep"

RUN apt-get update

RUN apt-get install -y openssh-server
RUN mkdir /var/run/sshd

RUN echo 'root:root' |chpasswd

RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config

RUN mkdir /root/.ssh

RUN apt-get clean && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

EXPOSE 22

CMD    ["/usr/sbin/sshd", "-D"]

 

 

 

posted @ 2019-03-11 19:27  酱_油  阅读(593)  评论(0编辑  收藏  举报