# 使用官方 CentOS 基础镜像(PS: latest版拉取openssh-server依赖报错)
FROM centos:centos7.9.2009
# 安装 SSH 服务
RUN yum install -y openssh-server
# 生成 SSH 密钥
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
RUN ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
RUN ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ''
# 设置 root 密码
RUN echo "root:password" | chpasswd
# 配置 SSH 服务
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
# 暴露 SSH 端口
EXPOSE 22
# 启动 SSH 服务
CMD ["/usr/sbin/sshd", "-D"]