From 762c19c00d5ec71ed5a9e288de171339fe9f7d1e Mon Sep 17 00:00:00 2001 From: Zherphy <1123678689@qq.com> Date: Wed, 4 Dec 2024 10:46:14 +0800 Subject: [PATCH] add: add ssh config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在dockerfile中配置ssh 设置ssh端口转发 --- DockerFile | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/DockerFile b/DockerFile index 4f5a885..7efb637 100644 --- a/DockerFile +++ b/DockerFile @@ -9,9 +9,41 @@ RUN go get github.com/akrylysov/algnhsa && \ FROM openeuler/openeuler:22.03 LABEL maintainer="Zhou Yi 1123678689@qq.com" RUN useradd -s /bin/bash BigFiles -USER BigFiles +USER root +#配置ssh服务 +RUN dnf -y update && \ + dnf -y install openssh && \ + dnf -y install openssh-server && \ + dnf -y install openssh-clients && \ + dnf -y install sshpass +RUN echo 'root:123456' | chpasswd +RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config + +WORKDIR /etc/ssh +#生成ssh服务本地秘钥 +RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N "" + +#编写ssh服务启动与端口转发脚本 +RUN echo '#!/bin/bash' > /port_forward.sh && \ + echo 'sshpass -p '123456' ssh -L 23231:gitee.com:22 -o ServerAliveInterval=20 -o StrictHostKeyChecking=no -gNf localhost' >> /port_forward.sh && \ + chmod +x /port_forward.sh + +RUN echo '#!/bin/bash' > /start.sh && \ + echo "/usr/sbin/sshd &" >> /start.sh && \ + echo "/port_forward.sh &" >> /start.sh && \ + echo "wait" >> /start.sh && \ + chmod +x /start.sh + +RUN echo '#!/bin/bash' > /begin.sh && \ + echo "/start.sh" >> /begin.sh && \ + echo "/start.sh" >> /begin.sh && \ + echo "/home/BigFiles/main \$1" >> /begin.sh && \ + chmod +x /begin.sh + WORKDIR /home/BigFiles COPY --chown=BigFiles:group --from=BUILDER /home/main /home/BigFiles/main +EXPOSE 23231 EXPOSE 5000 -ENTRYPOINT ["/home/BigFiles/main"] \ No newline at end of file + +ENTRYPOINT ["/begin.sh"]