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端口已被占用

相关推荐
晓梦.1 小时前
Vue3学习笔记
笔记·学习
思成不止于此1 小时前
【MySQL 零基础入门】DQL 核心语法(二):表条件查询与分组查询篇
android·数据库·笔记·学习·mysql
SadSunset2 小时前
(15)抽象工厂模式(了解)
java·笔记·后端·spring·抽象工厂模式
一点晖光3 小时前
Docker 作图咒语生成器搭建指南
python·docker
hd51cc3 小时前
MFC控件 学习笔记二
笔记·学习·mfc
Jack___Xue5 小时前
LangChain实战快速入门笔记(二)--LangChain使用之Model I/O
笔记·langchain
遇到困难睡大觉哈哈6 小时前
HarmonyOS —— Remote Communication Kit 拦截器(Interceptor)高阶定制能力笔记
笔记·华为·harmonyos
风123456789~6 小时前
【健康管理】第12章 健康信息学 2/2
笔记·考证·健康管理
hetao17338376 小时前
2025-12-11 hetao1733837的刷题笔记
c++·笔记·算法