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

相关推荐
江湖人称菠萝包26 分钟前
【Windows】《深入浅出Windows API程序设计:编程基础篇》笔记-Chapter8-子窗口控件
windows·笔记
lpfasd12335 分钟前
Docker存储清理与防膨胀实践
运维·docker·容器
M78佐菲1 小时前
HTML学习笔记
linux·笔记·学习·tcp/ip·html
weixin_444579302 小时前
Docker(下):镜像仓库管理
运维·docker·容器
我还可以再学点2 小时前
QUIC学习笔记
笔记·学习
DreamLife☼2 小时前
Agent开发环境搭建完全指南
python·docker·typescript·node·工业知识点
探索云原生2 小时前
Kueue + HAMi vGPU 实战:显存与算力配额管理
docker·ai·云原生·kubernetes·gpu
点心的游戏开发世界2 小时前
GDScript 入门笔记:目录
开发语言·笔记·游戏引擎·godot
山岚的运维笔记3 小时前
mysql 专业笔记 -- 第 17 章:连接:连接三个具有相同名称 ID 的表
运维·数据库·笔记·后端·学习·mysql·dba
hoho_123 小时前
docker中升级mysql到最新版本
mysql·docker·容器