From 2421fbedf873f33fafc408114ea36455254b5d89 Mon Sep 17 00:00:00 2001 From: wangzixiang <17839623189@163.com> Date: Tue, 4 Jun 2024 15:50:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 15 +++++++++++++++ LICENSE | 21 +++++++++++++++++++++ README.md | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..07a2c83 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM alpine +MAINTAINER ZK + +RUN apk add --update openssh-client && rm -rf /var/cache/apk/* + +CMD rm -rf /root/.ssh && mkdir /root/.ssh && cp -R /root/ssh/* /root/.ssh/ && chmod -R 600 /root/.ssh/* && \ +ssh \ +-C \ +-f \ +-N \ +-g \ +-p $REMOTE_PORT \ +-L $LOCAL_LISTEN_PORT:$LOCAL_LISTEN_HOST:$REMOTE_LISTEN_PORT $REMOTE_USER@$REMOTE_HOST \ +&& while true; do sleep 10; done; +EXPOSE 1-65535 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..de43622 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Attect + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d29cd4c --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# docker-ssh-forwarding +在Docker中使用SSH将远程服务器内部端口转发到本地内部网络 + +适合将生产环境中为了安全而不开放外部访问的端口,通过SSH安全转发功能,映射到内部网络指定主机和端口上。 + +## 凭证 +使用密钥登录,请提前将运行的用户的凭证放到远程服务器上(ssh-copy-id) + +## 构建 +``` +docker build . -t sshforwarding +``` + +## docker-compose.yml + +``` +version: "3" +services: + sshforwarding: + image: sshforwarding + container_name: sshforwarding + ports: + - "0.0.0.0:3307:3307" + volumes: + - $HOME/.ssh:/root/ssh:ro + environment: + REMOTE_USER: 远程服务器用户名 + REMOTE_HOST: 远程服务器主机名 + REMOTE_PORT: 远程服务器SSH端口 + REMOTE_LISTEN_PORT: 需要转发的服务器端口 + LOCAL_LISTEN_PORT: 本地监听端口 + LOCAL_LISTEN_HOST: "本地监听地址" +```