1. 公网服务器

自行参考以下项目:

 x86_64: Docker

arm64: Docker

2. 处于内网的办公机器

2.1 vpn客户端

        BIOS配置定时开机(一般在电源选项或者唤醒设置里)

        安装vpn客户端,配置好证书

        配置开机自动,参考配置

/usr/lib/systemd/system/openvpn.service 

[Unit]
Description=openvpn 2 dev
Documentation=man:ntpd(8)
After=network.target

[Service]
Type=simple
ExecStart=/bin/bash /home/yeqiang/bash_script/ovpn2dev.sh
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 /home/yeqiang/bash_script/ovpn2dev.sh

#!/bin/bash

sudo openvpn --config /home/yeqiang/Documents/openvpn-config/yeqiang-new2.ovpn

配置服务自启动

sudo systemctl daemon-reload
sudo systemctl enable openvpn --now

2.2 配置本地sshd 22端口转发

配置免密登录

sudo su
ssh-copy-id root@192.168.1.25

/home/yeqiang/bash_script/revertLocalhostSsh2Dev.sh

#!/bin/bash

while [ 1 -eq 1 ]
do
        date
        ssh -v -o ServerAliveInterval=10000 root@192.168.1.25 -R 2222:0.0.0.0:22 -N
        sleep 3
done

服务配置

/usr/lib/systemd/system/revertssh.service

[Unit]
Description=revert ssh 2 dev
After=openvpn.service

[Service]
Type=simple
ExecStart=/bin/bash /home/yeqiang/bash_script/revertLocalhostSsh2Dev.sh
PrivateTmp=true

[Install]
WantedBy=multi-user.target

开启启动配置

sudo systemctl daemon-reload
sudo systemctl enable revertssh --now

2.3 创建专用用户

useradd sshproxy
#交互式设置密码
passwd sshproxy

3.处于公网vpn内部网络的服务器

映射的端口状态

注意Localhost Address 是127.0.0.1,只允许本地接入

部署一个nginx,将此127.0.0.1:2222暴露到0.0.0.0:12222

编译配置项

configure arguments: --with-stream 

nginx.conf

# 转到公司  电脑的代理
stream {
	upstream office_yeqiang_proxy {
		server 127.0.0.1:2222;
	}
	server {
		listen 12222;
		proxy_responses 1;
		proxy_timeout 120s;
		proxy_pass office_yeqiang_proxy;
	}
}

4. 处于公网(家里)的电脑

4.1 用同样的vpn拨入

4.2 直接连接映射出来的12222端口,获得一个具有办公内网的shell

ssh yeqiang@192.168.1.25 -p 2222

4.3 连接成功后,即可在shell内访问任意内网资源

5. 图形界面

5.1 处于公司的办公机器

安装tigervnc

sudo apt install tigervnc-standalone-server tigervnc-common -y

/usr/lib/systemd/system/vncserver.service

[Unit]
Description=Remote desktop service (VNC)
After=openvpn.service

[Service]
Type=forking
User=sshproxy
Group=sshproxy
Environment="HOME=/home/sshproxy"
Environment="DISPLAY=:0"
Environment="XAUTHORITY=/home/sshproxy/.Xauthority"
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'

[Install]
WantedBy=multi-user.target

配置vnc用户账号密码

sudo su sshproxy
# 交互式设置密码
vncpasswd

服务自启动

sudo systemctl daemon-reload
sudo systemctl enable vncserver --now

网络状态

创建端口转发脚本及服务

/home/yeqiang/bash_script/revertLocalhostVnc2Dev.sh

#!/bin/bash
  
while [ 1 -eq 1 ]
do
        date
        ssh -v -o ServerAliveInterval=10000 root@192.168.1.25 -R 5901:0.0.0.0:5901 -N
        sleep 3
done

/usr/lib/systemd/system/revertvnc.service

[Unit]
Description=revert vnc 2 dev
After=openvpn.service

[Service]
Type=simple
ExecStart=/bin/bash /home/yeqiang/bash_script/revertLocalhostVnc2Dev.sh
PrivateTmp=true

[Install]
WantedBy=multi-user.target

启动服务

sudo systemctl daemon-reload
sudo systemctl enable revertvnc --now

5.2 处于公网vpn的内部服务器

 nginx.conf

        upstream office_yeqiang_proxy_vnc {
                server 127.0.0.1:5901;
        }
        server {
                listen 15901;
                proxy_responses 1;
                proxy_timeout 120s;
                proxy_pass office_yeqiang_proxy_vnc;
        }

5.3 家里的电脑

vncviewer 192.168.1.25:15901

Logo

更多推荐