Skip to content

Commit

Permalink
add: add ssh config
Browse files Browse the repository at this point in the history
在dockerfile中配置ssh
设置ssh端口转发
  • Loading branch information
Zherphy committed Dec 4, 2024
1 parent 5fe05cb commit 762c19c
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions DockerFile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,41 @@ RUN go get github.com/akrylysov/algnhsa && \
FROM openeuler/openeuler:22.03
LABEL maintainer="Zhou Yi [email protected]"
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"]

ENTRYPOINT ["/begin.sh"]

0 comments on commit 762c19c

Please sign in to comment.