制作带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服务器端。
如下:
- [root@aefe8007a17d ~]# /usr/sbin/sshd
- Could not load host key: /etc/ssh/ssh_host_rsa_key
- Could not load host key: /etc/ssh/ssh_host_ecdsa_key
- 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
- [root@aefe8007a17d ~]# ll /etc/ssh/
- total 276
- -rw-r--r-- 1 root root 242153 Mar 21 22:18 moduli
- -rw-r--r-- 1 root root 2208 Mar 21 22:18 ssh_config
- -rw------- 1 root root 227 May 22 16:48 ssh_host_ecdsa_key
- -rw-r--r-- 1 root root 179 May 22 16:48 ssh_host_ecdsa_key.pub
- -rw------- 1 root root 411 May 22 16:48 ssh_host_ed25519_key
- -rw-r--r-- 1 root root 99 May 22 16:48 ssh_host_ed25519_key.pub
- -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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器