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

相关推荐
芝士雪豹只抽瑞克五4 分钟前
Linux Virtual Server (LVS) 负载均衡集群笔记
linux·笔记·负载均衡·lvs
兴趣使然黄小黄11 分钟前
【Docker】Docker架构详解:核心组件及其应用指南
docker·容器·架构
Houz-17 分钟前
【13180】 计算机操作系统第一章操作系统概论——第一节操作系统概念
笔记·职场和发展·学习方法
luod18 分钟前
Docker 快速安装Jenkins
java·docker·jenkins
三水不滴19 分钟前
利用SpringCloud Gateway 重试 + 降级解决第三方接口频繁超时问题,提升性能
经验分享·笔记·后端·spring·spring cloud·gateway
charlie11451419120 分钟前
嵌入式C++教程——Lambda捕获与性能影响
开发语言·c++·笔记·嵌入式·现代c++·工程实践
一目Leizi22 分钟前
澳洲 IoT 网络安全规则(Cyber Security 2025)与英国 PSTI 笔记
笔记·物联网·web安全
左左右右左右摇晃22 分钟前
WebSocket 与 HTTP 的核心区别
笔记
声声长乐8 小时前
Jenkins + Docker 完整部署指南
ubuntu·docker·jenkins
雾岛听蓝11 小时前
C++11新特性(lambda、包装器)
c++·经验分享·笔记