用密码登录root

docker官网给的sshdemo是ubuntu的,https://docs.docker.com/engine/examples/running_ssh_service/
 
亲测可以
 
FROM ubuntu:16.04
RUN apt update
#sshd
RUN apt install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:aaaa' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config # SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile EXPOSE 22 CMD ["/usr/sbin/sshd", "-D"]

但python的官方镜像是基于debian的,用上面这个不行。

参考这个 https://github.com/Azure-Samples/docker-django-webapp-linux/blob/master/Dockerfile

其实是python的debian里sshd_config选项的区别:

众所周知,sshd_config是sshd的配置文件,其中PermitRootLogin可以限定root用户通过ssh的登录方式,如禁止登陆、禁止密码登录、仅允许密钥登陆和开放登陆,以下是对可选项的概括:

参数类别 是否允许ssh登陆 登录方式 交互shell
yes 允许 没有限制 没有限制
without-password 允许 除密码以外 没有限制
forced-commands-only 允许 仅允许使用密钥 仅允许已授权的命令
no 不允许 N/A N/A

以上选项中,yes和no的功能显而易见,只是很粗暴的允许、禁止root用户进行登陆。without-password在yes的基础上,禁止了root用户使用密码登陆。

不知为什么 ubuntu里不是without-password,而python /debian 里是。所以要用密码登录,得
FROM python
LABEL author="xuqinghan"
LABEL purpose = '' RUN apt-get update \
&& apt-get -q -y dist-upgrade \
&& apt-get -q -y install --no-install-recommends openssh-server
#&& apt-get clean \
#&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN mkdir /var/run/sshd
RUN echo 'root:aaaa' | chpasswd RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config # SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile EXPOSE 22 CMD ["/usr/sbin/sshd", "-D"]

只改了一个地方,其他和ubuntu保持一样

 

用公钥

只要把本机的ida_rsa.pub上传到容器里就OK了,容器扮演的角色 和Github一样。container里运行着openssh server,host作为客户端去连接ssh server。

只不过,ida_rsa.pub的位置要注意,dockerfile的语法里ADD 要绝对路径 ,COPY 要 当前dockerfile路径和子路径 才能用相对路径。

所以为了简单起见,还是直接在外面复制出ida_rsa.pub到当前工程,然后再COPY。

如果有多个客户端(再说)

FROM python
LABEL author="xuqinghan"
LABEL purpose = '' RUN apt-get update \
&& apt-get -q -y dist-upgrade \
&& apt-get -q -y install --no-install-recommends openssh-server
#&& apt-get clean \
#&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* RUN mkdir /var/run/sshd
RUN echo 'root:aaaa' | chpasswd RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config #在外面复制出id_rsa.pub
#cp ~/.ssh/id_rsa.pub ~/dev/id_rsa.pub COPY id_rsa.pub /root/.ssh/authorized_keys # SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile EXPOSE 22 CMD ["/usr/sbin/sshd", "-D"]
 

ssh连接docker镜像ubuntu与debian的更多相关文章

  1. ssh连接docker容器

    有两种方法: 1.通过宿主机的端口映射访问docker 在宿主机上启动容器,分配端口,启用ssh服务: docker run -p 10022:22 -d sshd:ubuntu /usr/sbin/ ...

  2. windows 使用ssh连接docker容器

    在Windows上搭建docker服务器需要在Windows模拟一个Linux平台,然后在Linux平台上搭建的docker服务器,所以在使用ssh工具连接docker容器的时候,使用的ip地址不是d ...

  3. Docker制作能够ssh连接的镜像

    本类文章只作为记录使用 命令操作: #拉取Centos 7 docker pull centos:7 #运行一个镜像 docker run -tdi --privileged centos:7 ini ...

  4. 不能ssh连接ubuntu linux 服务器 secureCRT不能ssh连接服务器 不能远程ssh连接虚拟机的ubuntu linux

    我是用的是secureCRT,远程连接我的虚拟机里面的ubuntu 直接报错,连接不上 1,先分别在windows上ipconfig和ubuntu上ifconfig下 互ping一下,是可以ping通 ...

  5. 【ssh连接docker container问题】

    在向docker container执行ssh或scp的时候,应该将docker container的22端口映射出来,然后ssh/scp命令指定映射出来的端口

  6. docker镜像ubuntu封装jdk1.8.0【dockerfile】

    github地址:https://github.com/laileman/Docker/Dockerfile/ubuntu-jdk1.8.0_172 1-目录结构 2- dockerfile内容 3- ...

  7. ssh 连接ubuntu的虚拟机问题

    我在winxp的虚拟机上装了一个ubuntu9.04的系统,winxp的ip为10.118.62.157,ubuntu的ip为192.168.116.1 两个ip互相ping都是正常的,但是,我在wi ...

  8. window用ssh连接本机虚拟机中的ubuntu

    @window用ssh连接本机虚拟机中的ubuntu 主机和虚拟机间通信,需将2台机器的IP地址设为同一网段. 1.设置虚拟机: 虚拟机–> 设置–> Hardware –> Net ...

  9. 【玩转开源】制作Docker镜像

    做嵌入式方向经常会遇到的一个问题,就是编译环境安装,如果换电脑,再重新安装环境是一个比较费时的事情,这个时候可以自己制作一个Docker镜像,然后把编译环境在Docker镜像里面配置好,以后同步环境就 ...

随机推荐

  1. python面向对象三大特性之一继承、多态、封装

    继承,即在定义一个类时,以另一个类为参数,则称这个新定义的类继承了参数类,父类又称为基类. 单继承表示只继承一个类,多继承表示继承多个类. class parent1: pass class pare ...

  2. Spring Maven 包的依赖

    <properties> <spring.version>4.3.11.RELEASE</spring.version> </properties> & ...

  3. JVM优化-JVM参数配置

    配置方式: java [options] MainClass [arguments] options - JVM启动参数. 配置多个参数的时候,参数之间使用空格分隔. 参数命名: 常见为 -参数名 参 ...

  4. Vue 旅游网首页开发1-工具安装及码云使用

    Vue 旅游网首页开发-工具安装及码云使用 环境安装 安装 node.js node.js 官网:https://nodejs.org/en/ 注册码云,创建私密仓库存储项目 码云:https://g ...

  5. python简说(二十九)线程,进程

    进程: 一些资源的集合. 一个进程里面最少有一个线程,主线程.线程: 程序执行的最小单位. import threadingfrom threading import Threadimport tim ...

  6. bzoj 2936 [Poi 1999] 降水 - 并查集

    题目传送门 需要root权限的传送门 题目大意 有一个$n\times m$的网格图,每一格都有一个高度.一次降雨过后问最多能积多少水. 考虑算每一高度能储存的水的量. 如果小于等于这个高度的格子和边 ...

  7. ./configure: error: C compiler cc is not found

    没有安装gcc 在安装nginx之前先安装依赖软件 yum install -y gcc gcc-c++ autoconf pcre pcre-devel make automake wget htt ...

  8. ODAC(V9.5.15) 学习笔记(十四)TCRBatchMove

    名称 类型 说明 AbortOnKeyViol Boolean 在处理数据时,如果发生主键冲突或主键校验失败时,是否中断 AbortOnProblem Boolean 发生问题时是否中断 Change ...

  9. DataSnap下的分包获取

    DataSnap下通过TQuery—TDataSetProvider—TClientDataSet获取数据,如果是主从数据,则每条主表记录都会触发从表数据的获取. 这种获取和组织数据的方式有一个问题: ...

  10. Bootstrap3基础 navbar 导航条 简单示例

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...