forked from metalogical/BigFiles
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
在dockerfile中配置ssh 设置ssh端口转发
- Loading branch information
Showing
1 changed file
with
34 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"] |