Docker Centos安装Openssh

简介:

Docker Centos安装Openssh

环境介绍:

    Docker版本:1.5.0

    镜像:docker.io:centos latest

操作步骤:

    1、启动镜像

docker run -ti centos /bin/bash

    2、安装passwd

yum install passwd -y

   3、修改Centos root密码

# passwdChanging password for user root.
New password: 123456BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 123456passwd: 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:33:3c:34:49:e4:76:7d:45:cc:69:ac:46:85:ab:27:9e root@378ab88a06c8
The key's randomart image is:+--[ RSA 2048]----+
|       .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:09:ac:b0:61:55:de:e8:4f:5e:20:d9:fc:1e:b6:d7:79 root@378ab88a06c8
The key's randomart image is:+--[ RSA 2048]----+
|    ...          |
|   . 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:63:0d:b5:fb:55:a4:56:47:43:6d:68:c0:47:2e:84:24 root@378ab88a06c8
The key's randomart image is:+--[ RSA 2048]----+
|        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 222

   8、退出容器,保存镜像

[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
378ab88a06c8        centos:latest       "/bin/bash"         52 minutes ago      Exited (0) 29 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        2 minutes ago       271.3 MB192.168.31.202:5000/test   latest              f6c0d93ac266        3 days ago          315.6 MB
docker.io/centos           latest              fd44297e2ddb        3 weeks ago         215.7 MB
docker.io/busybox          latest              8c2e06607696        4 weeks ago         2.43 MB
[root@localhost ~]# docker run --net=host -d sshd:centos /run.shbbd39bbd7e03ffbd22b88725041793c74c50dbd4316d25bd20c8053265c3f8f1

   9、远程连接测试

[root@localhost ~]# ssh 192.168.31.203 -p 222The authenticity of host '[192.168.31.203]:222 ([192.168.31.203]:222)' can't be established.RSA key fingerprint is 79:2f:94:52:bb:22:8c:32:f2:2c:0d:82:cb:b2:26:75.
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 23 07:23:32 2015 from 192.168.7.46[root@localhost ~]# ll
total 0[root@localhost ~]# cd /[root@localhost /]# ll
total 44lrwxrwxrwx   1 root root    7 Apr 15 14:28 bin -> usr/bin
drwxr-xr-x   5 root root  360 Jun 23 07:22 dev
drwxr-xr-x  48 root root 4096 Jun 23 07:22 etc
drwxr-xr-x   2 root root 4096 Jun 10  2014 home
lrwxrwxrwx   1 root root    7 Apr 15 14:28 lib -> usr/lib
lrwxrwxrwx   1 root root    9 Apr 15 14:28 lib64 -> usr/lib64
drwx------   2 root root 4096 Apr 15 14:26 lost+found
drwxr-xr-x   2 root root 4096 Jun 10  2014 media
drwxr-xr-x   2 root root 4096 Jun 10  2014 mnt
drwxr-xr-x   2 root root 4096 Jun 10  2014 opt
dr-xr-xr-x 348 root root    0 Jun 23 07:22 proc
dr-xr-x---   2 root root 4096 Jun  4 02:20 root
drwxr-xr-x  11 root root  240 Jun 23 07:22 run-rwxr-xr-x   1 root root   30 Jun  4 02:19 run.shlrwxrwxrwx   1 root root    8 Apr 15 14:28 sbin -> usr/sbin
drwxr-xr-x   2 root root 4096 Jun 10  2014 srv
dr-xr-xr-x  13 root root    0 May 15 07:27 sys
drwxrwxrwt   7 root root  140 Jun 23 07:30 tmp
drwxr-xr-x  13 root root 4096 Apr 15 14:28 usr
drwxr-xr-x  19 root root 4096 Apr 15 14:29 var
[root@localhost /]#


本文转自 Mr_sheng 51CTO博客,原文链接:http://blog.51cto.com/sf1314/1981259

相关文章
|
5天前
|
缓存 Ubuntu Linux
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
通过本文,我们详细了解了 `yum`、`rpm`、`apt-get`和 `wget`的区别、常用命令以及在CentOS和Ubuntu中安装 `wget`的方法。`yum`和 `apt-get`是高层次的包管理器,分别用于RPM系和Debian系发行版,能够自动解决依赖问题;而 `rpm`是低层次的包管理工具,适合处理单个包;`wget`则是一个功能强大的下载工具,适用于各种下载任务。在实际使用中,根据系统类型和任务需求选择合适的工具,可以大大提高工作效率和系统管理的便利性。
54 25
|
22天前
|
关系型数据库 MySQL 数据库
Docker Compose V2 安装常用数据库MySQL+Mongo
以上内容涵盖了使用 Docker Compose 安装和管理 MySQL 和 MongoDB 的详细步骤,希望对您有所帮助。
122 42
|
15天前
|
监控 Linux PHP
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
【02】客户端服务端C语言-go语言-web端PHP语言整合内容发布-优雅草网络设备监控系统-2月12日优雅草简化Centos stream8安装zabbix7教程-本搭建教程非docker搭建教程-优雅草solution
65 20
|
26天前
|
Linux Docker 容器
安装docker-18.06报错Error: libseccomp conflicts with docker-18.06
通过这些步骤,您可以成功在CentOS上安装Docker 18.06,并解决libseccomp的冲突问题。这些方法确保系统兼容性,并保证Docker的正常运行。
60 27
|
15天前
|
Ubuntu API 网络虚拟化
ubuntu22 编译安装docker,和docker容器方式安装 deepseek
本脚本适用于Ubuntu 22.04,主要功能包括编译安装Docker和安装DeepSeek模型。首先通过Apt源配置安装Docker,确保网络稳定(建议使用VPN)。接着下载并配置Docker二进制文件,创建Docker用户组并设置守护进程。随后拉取Debian 12镜像,安装系统必备工具,配置Ollama模型管理器,并最终部署和运行DeepSeek模型,提供API接口进行交互测试。
241 15
|
26天前
|
网络协议 Linux 网络安全
docker centos镜像 npm安装包时报错“npm ERR! code ECONNRESET”
通过上述步骤,您可以有效解决在 Docker 中使用 CentOS 镜像安装 npm 包时遇到的 "npm ERR! code ECONNRESET" 错误。希望这些方法能帮助您顺利进行 npm 包的安装。
122 26
|
14天前
|
消息中间件 Kafka Docker
docker compose 安装 kafka
通过本文的步骤,您可以快速在本地使用 Docker Compose 安装并配置 Kafka 和 Zookeeper。Docker Compose 简化了多容器应用的管理,方便快速搭建和测试分布式系统。
56 2
|
1月前
|
前端开发 应用服务中间件 nginx
docker安装nginx,前端项目运行
通过上述步骤,你可以轻松地在Docker中部署Nginx并运行前端项目。这种方法不仅简化了部署流程,还确保了环境的一致性,提高了开发和运维的效率。确保按步骤操作,并根据项目的具体需求进行相应的配置调整。
148 25
|
1月前
|
安全 数据安全/隐私保护 Docker
docker私有仓库harbor安装
通过以上步骤,您可以成功在企业内部安装和配置Harbor私有仓库,方便地管理和分发Docker镜像。Harbor不仅提供了基础的镜像管理功能,还增强了安全性、身份管理和审计功能,使其成为企业级容器镜像管理的理想选择。
109 22
|
1月前
|
存储 Shell 网络安全
Centos7.9安装openldap
Centos7.9安装openldap
58 16