上传文件至 /

This commit is contained in:
wangzixiang 2024-06-04 15:50:00 +08:00
commit 2421fbedf8
3 changed files with 69 additions and 0 deletions

15
Dockerfile Normal file
View File

@ -0,0 +1,15 @@
FROM alpine
MAINTAINER ZK <zkalgclub@163.com>
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

21
LICENSE Normal file
View File

@ -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.

33
README.md Normal file
View File

@ -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: "本地监听地址"
```