随笔 - 91  文章 - 0  评论 - 2  阅读 - 44255

制作带sshd功能的centos镜像

docker run -it --name node1 docker.io/centos bash  创建node1容器

docker exec -it node1 bash 进入node1

 

yum install openssh-server –y    安装ssh

yum install net-tools –y  安装ifconfig

 

现象:启动sshd服务时,虽看似服务启动成功,但客户端并不能连接上sshd服务器端。
如下:

  1. [root@aefe8007a17d ~]# /usr/sbin/sshd

  2. Could not load host key: /etc/ssh/ssh_host_rsa_key
  3. Could not load host key: /etc/ssh/ssh_host_ecdsa_key
  4. Could not load host key: /etc/ssh/ssh_host_ed25519_key

 

cd /etc/ssh/  创建密钥

ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key

 ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key

ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key

 

  1. [root@aefe8007a17d ~]# ll /etc/ssh/

  2. total 276
  3. -rw-r--r-- 1 root root 242153 Mar 21 22:18 moduli
  4. -rw-r--r-- 1 root root 2208 Mar 21 22:18 ssh_config
  5. -rw------- 1 root root 227 May 22 16:48 ssh_host_ecdsa_key
  6. -rw-r--r-- 1 root root 179 May 22 16:48 ssh_host_ecdsa_key.pub
  7. -rw------- 1 root root 411 May 22 16:48 ssh_host_ed25519_key
  8. -rw-r--r-- 1 root root 99 May 22 16:48 ssh_host_ed25519_key.pub
  9. -rw------- 1 root root 1679 May 22 16:48 ssh_host_rsa_key

10. -rw-r--r-- 1 root root 399 May 22 16:48 ssh_host_rsa_key.pub

11. -rw------- 1 root root 4361 Mar 21 22:18 sshd_config

 

/usr/sbin/sshd &  开启ssh

 

netstat -ntlup|grep 22 查看端口

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      32/sshd            

tcp6       0      0 :::22                   :::*                    LISTEN      32/sshd

 

passwd修改root密码

 

做成镜像

docker commit -m  'add centos_sshd images'  node1  new/centos_sshd

                                                                       此容器名     新镜像名

 

查看镜像

docker images

 

用镜像生成的容器不需要端口映射即可远程

 

登陆(用户/密码 hello/123456)

docker login 127.0.0.1:5000

 

重命名

docker tag 276408de9b28 127.0.0.1:5000/hello/centos_sshd

 

上传

docker push 127.0.0.1:5000/hello/centos_sshd

 

查看是否上传成功

docker images

posted on   SZ_文彬  阅读(247)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示