Docker笔记-Debian容器内搭建ssh服务

登陆容器之后修改密码:

bash 复制代码
passwd

密码设置完成后安装openssh-server

bash 复制代码
apt-get install openssh-server

修改端口号为50022并添加配置

bash 复制代码
vim /etc/ssh/sshd_config

修改成

bash 复制代码
Port 50022
PasswordAuthentication yes
PermitRootLogin yes

启动

bash 复制代码
root@linux:~# /etc/init.d/ssh start
[ ok ] Starting OpenBSD Secure Shell server: sshd.

查看

bash 复制代码
root@linux:~# /etc/init.d/ssh status
[ ok ] sshd is running.

--net修改.bashrc,运行容器后就启动ssh

在最后面添加:

bash 复制代码
/etc/init.d/ssh start

保存镜像

启动时注--net=host这样就可以用50022登陆了

bash 复制代码
docker run --net=host -it 容器名 /bin/bash

最终在宿主机可见:

50022端口已被占用

相关推荐
宋均浩2 小时前
# Docker 镜像瘦身实战:从 1.2G 到 80MB 的五个优化步骤
ci/cd·docker
程序员老赵18 小时前
10 分钟部署 OpenCode:Docker 一键安装,浏览器打开就能用 AI 写代码(附完整命令与排错)
docker·容器·ai编程
WangMingHua1111 天前
LM Studio Docker 部署——本地大模型一键启动
docker
曲幽2 天前
别再用网页翻译看源码了!你的私人翻译神器LibreTranslate,部署避坑指南来了
python·docker·web·pot·translate·libretranslate·arogstranslate
LinXunFeng3 天前
Obsidian - 使用 Share Note 分享笔记并自部署
前端·笔记·github
武子康4 天前
调查研究-183 Apple container:Mac 上用轻量 VM 跑 Linux 容器,Swift 会改写本地容器体验吗?
docker·容器·apple
Alsn867 天前
等待学习-学习目录:Docker 容器安全攻防
学习·安全·docker
闪闪发亮的小星星7 天前
高斯光以及高斯光公式解释
笔记
cqbzcsq7 天前
CellFlow虚拟细胞论文阅读
论文阅读·人工智能·笔记·学习·生物信息
2601_961875247 天前
决战申论100题2026|最新|范文
linux·容器·centos·debian·ssh·fabric·vagrant