目的:让你的内网设备能随时被外网设备访问
公网
1.修改配置文件/etc/ssh/sshd_config GatewayPorts yes
2. 重启ssh服务使配置生效sudo service ssh restart
内网
1. 安装autossh sudo apt install autossh
2. 生成密钥 ssh-keygen
3. 想远程服务器发送密钥 ssh-copy-id root@43.138.34.13
4. 新建service服务,目录为/lib/systemd/system/auto.service
[Unit]
Description=autossh
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
Environment="AUTOSSH_GATETIME=0"
User=root
Group=root
WorkingDirectory=/home
ExecStart=/usr/bin/autossh -M 4010 -NR 9999:localhost:8000 root@43.138.34.13
[Install]
WantedBy=multi-user.target
5.设置开机自启 sudo systemctl enable autossh.service
6.开启服务sudo systemctl start autossh.service
评论区