环境介绍:

Docker版本:1.5.0

镜像:docker.io:centos latest

操作步骤:

1、启动镜像

docker run -ti centos /bin/bash

2、安装passwd

yum install passwd -y

3、修改Centos root密码

# passwd
Changing password for user root.
New password:
BAD PASSWORD: The password is shorter than characters
Retype new password:
passwd: all authentication tokens updated successfully.

4、安装openssh

yum install openssh-server -y

5、生成公钥、私钥

[root@378ab88a06c8 /]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): (直接回车)
Enter same passphrase again: (直接回车)
Your identification has been saved in /etc/ssh/ssh_host_rsa_key.
Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub.
The key fingerprint is:
:3c:::e4::7d::cc::ac:::ab::9e root@378ab88a06c8
The key's randomart image is:
+--[ RSA ]----+
| .o +=+|
| o . . o =o|
| * . o = |
| + o = |
| S o |
| + o . |
| . + |
| E |
| |
+-----------------+
[root@378ab88a06c8 /]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_ecdsa_key
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): (直接回车)
Enter same passphrase again: (直接回车)
Your identification has been saved in /etc/ssh/ssh_host_ecdsa_key.
Your public key has been saved in /etc/ssh/ssh_host_ecdsa_key.pub.
The key fingerprint is:
:ac:b0:::de:e8:4f:5e::d9:fc:1e:b6:d7: root@378ab88a06c8
The key's randomart image is:
+--[ RSA ]----+
| ... |
| . o * |
| + B = |
| . + o o + |
| . . . S = |
| + + o . . |
| o o . o E|
| . . |
| |
+-----------------+
[root@378ab88a06c8 /]# ssh-keygen -t rsa -f /etc/ssh/ssh_host_ed25519_key
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): (直接回车)
Enter same passphrase again: (直接回车)
Your identification has been saved in /etc/ssh/ssh_host_ed25519_key.
Your public key has been saved in /etc/ssh/ssh_host_ed25519_key.pub.
The key fingerprint is:
:0d:b5:fb::a4::::6d::c0::2e:: root@378ab88a06c8
The key's randomart image is:
+--[ RSA ]----+
| E.ooooo=*|
| o.o..++=|
| . . .o+..|
| o . o . |
| S o . |
| . . . . |
| . |
| |
| |
+-----------------+

6、编写启动脚本

# vi /run.sh

#!/bin/bash
/usr/sbin/sshd -D # chmod +x /run.sh

7、修改SSH默认端口

# vi /etc/ssh/sshd_config 

Port 

8、退出容器,保存镜像

[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
378ab88a06c8 centos:latest "/bin/bash" minutes ago Exited () seconds ago ecstatic_hawking
[root@localhost ~]# docker commit 378ab88a06c8 sshd:centos
9f400c5422109a3403779f4b055c673fae57d1a8809a84bad7a20fcc3574b3dc

8、启动容器

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
sshd centos 9f400c542210 minutes ago 271.3 MB
192.168.31.202:/test latest f6c0d93ac266 days ago 315.6 MB
docker.io/centos latest fd44297e2ddb weeks ago 215.7 MB
docker.io/busybox latest 8c2e06607696 weeks ago 2.43 MB
[root@localhost ~]# docker run --net=host -d sshd:centos /run.sh
bbd39bbd7e03ffbd22b88725041793c74c50dbd4316d25bd20c8053265c3f8f1

9、远程连接测试

[root@localhost ~]# ssh 192.168.31.203 -p
The authenticity of host '[192.168.31.203]:222 ([192.168.31.203]:222)' can't be established.
RSA key fingerprint is :2f:::bb::8c::f2:2c:0d::cb:b2::.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.31.203]:222' (RSA) to the list of known hosts.
root@192.168.31.203's password:
Last login: Tue Jun :: from 192.168.7.46
[root@localhost ~]# ll
total
[root@localhost ~]# cd /
[root@localhost /]# ll
total
lrwxrwxrwx root root Apr : bin -> usr/bin
drwxr-xr-x root root Jun : dev
drwxr-xr-x root root Jun : etc
drwxr-xr-x root root Jun home
lrwxrwxrwx root root Apr : lib -> usr/lib
lrwxrwxrwx root root Apr : lib64 -> usr/lib64
drwx------ root root Apr : lost+found
drwxr-xr-x root root Jun media
drwxr-xr-x root root Jun mnt
drwxr-xr-x root root Jun opt
dr-xr-xr-x root root Jun : proc
dr-xr-x--- root root Jun : root
drwxr-xr-x root root Jun : run
-rwxr-xr-x root root Jun : run.sh
lrwxrwxrwx root root Apr : sbin -> usr/sbin
drwxr-xr-x root root Jun srv
dr-xr-xr-x root root May : sys
drwxrwxrwt root root Jun : tmp
drwxr-xr-x root root Apr : usr
drwxr-xr-x root root Apr : var
[root@localhost /]#

Docker Centos安装Openssh的更多相关文章

  1. Docker Centos安装Redis以及问题处理

    之前一篇文章 Redis安装及主从配置 介绍了redis的安装配置,另一篇文件介绍了 Docker Centos安装Openssh .今天将两篇文件结合一下——在Docker Centos环境下搭建r ...

  2. Docker Centos安装Mysql5.6

    之前一篇随笔<Docker Centos安装Openssh> 写的是如何在基础的centos镜像中搭建ssh服务,在此基础上再搭建其他服务.本文继续介绍在centos_ssh基础上搭建my ...

  3. Docker - CentOS 安装 Docker 和 Docker-Compose

    目录 介绍 Docker Docker-Conpose 安装 Docker CE 系统要求 使用 YUM 安装 配置加速器 安装 Docker-Compose 介绍 Docker Docker 是一个 ...

  4. Docker - CentOS安装Docker

    如果要在CentOS下安装Docker容器,必须是CentOS 7 (64-bit).CentOS 6.5 (64-bit) 或更高的版本,并要求 CentOS 系统内核高于 3.10. uname ...

  5. 1、docker centos 安装

    Docker for CentOS: 第一步:使用官方yum仓库 [root@linux-node1 ~]# yum install -y yum-utils [root@linux-node1 ~] ...

  6. Docker centos 安装syslog

    在通常的Linux服务器中,有一些服务本身没有日志,只能通过 tail -f /var/log/messages来查看其运行日志,比如nrpe server.但是,如果想在docker容器中实现这个功 ...

  7. 4、Docker的安装

      docker官方安装文档 Mac上安装Docker   Install Docker for Mac | Docker Documentation Windows安装Docker   Instal ...

  8. centos安装docker容器

    centos安装docker容器 系统环境需求 docker要运行在centos7系统中,系统为64位机器上,内核最小版本在3.10以上 如果系统为centos6,后面有附带的安装方法 uname - ...

  9. 在centos,docker中安装HeadlessChrome

    在centos6中安装chrome与chrome-driver,中间走了很多弯路,遇到很多坑,现将详细步骤总结如下.参考博客链接:https://blog.csdn.net/u013849486/ar ...

随机推荐

  1. uwsgi + nigix + django的样式展示

    编辑添加黄色部分  是你的项目目录  在你的项目目录写的静态文件 内的样式调用的是static 如果不是 请改名 [root@ayibang-server s10day11]# vim /etc/ng ...

  2. Activity的四种启动模式-图文并茂

    1.对于使用standard 模式的活动,系统不会在乎这个活动是否已经在返回栈中存在,每次启动都会创建该活动的一个新的实例.   例如A启动A,A再接着启动A,A继续启动A,然后再分别出栈,如图所示 ...

  3. 第三篇 Replication:事务复制-发布服务器

    本篇文章是SQL Server Replication系列的第三篇,详细内容请参考原文. 发布服务器是所有复制数据的源头.每一个发布服务器上可以定义多个发布.每一个发布包含一组项目(项目在同一个数据库 ...

  4. MAC下Android的Eclipse开发环境的搭建

    一.Eclipse的下载 到网站:http://www.eclipse.org/downloads/ 上,由于我们是用Java开发的所以步骤如下: 1.  找到"Eclipse IDE fo ...

  5. eclipse中运行Selenium遇到的问题

    1.   java.lang.NoClassDefFoundError: 解决方法:eclipse的java工程中导入selenium-java-2.44.0\selenium-2.44.0\libs ...

  6. [GDAL]读取HDF格式的calipso数据

    探测地球云层分布的CloudSat和CALIPSO卫星 http://www.nasa.gov/mission_pages/calipso/main/index.html http://www.nas ...

  7. underscore源码解析

    (function() { // 创建一个全局对象, 在浏览器中表示为window对象, 在Node.js中表示global对象 var root = this; // 保存"_" ...

  8. javascript实例学习之五——瀑布流布局

    瀑布流布局的特征: 1,各列的高度参差不齐 2,页面向下滚动时,自动请求和加载新数据 目前,瀑布流布局的主流实现方式有两种: 1,基于浮动,每一列是一个ul,这些ul都向左浮动,这种方法的好处是布局容 ...

  9. 学习OpenCV——配置CUDA环境

    大家都把GPU&CUDA说的很NB狠NB,于是,下一步想通过GPU加速程序运行.这一个星期,都在配置OpenCV的CUDA环境,今天终于以失败告终,原因是实验室的机器显卡不支持CUDA...伤 ...

  10. 监控linux服务器网卡流量

    监控linux服务器网卡流量 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.       欢迎加入:高级运维工程师之路 598432640 前言:众所周知,我们安装zabbix服务器 ...