了解关于SSH-Tunnel的常见问题和解决方案
SSH-Tunnel是一个基于SSH协议建立安全隧道并提供本地代理服务的工具。它的工作原理如下:
这种方式提供了几个优势:
如果您在连接SSH服务器时遇到问题,请按照以下步骤排查:
ssh -i /path/to/private_key username@server_ip-admin.enable 启动SSH-Tunnel并查看管理界面上的日志SSH-Tunnel已经内置了自动重连机制,但如果您仍然遇到连接不稳定的问题,可以尝试以下解决方案:
使用 -retry.interval.sec 参数调整重连间隔时间(默认为3秒):
./ssh-tunnel -s your_server -retry.interval.sec 5
在服务器的 /etc/ssh/sshd_config 文件中添加或修改以下配置:
TCPKeepAlive yes
ClientAliveInterval 30
ClientAliveCountMax 3
修改后重启SSH服务:sudo systemctl restart sshd
将SSH-Tunnel配置为系统服务(Windows服务或Linux/MacOS守护进程),这样在发生崩溃时系统会自动重启服务
启用管理界面并监控日志,查找可能导致断开的原因
域名过滤功能允许您指定哪些域名的请求通过SSH隧道转发,而其他域名则直接访问。这在以下场景中特别有用:
domain.txt),每行一个域名模式:*.google.com
*.github.com
github.com
*.stackoverflow.com
./ssh-tunnel -s your_server -http.enable -http.domain-filter.enable -http.domain-filter.file-path /path/to/domain.txt
如果启用了管理界面,您可以在Web界面上动态添加、删除和修改域名列表,无需重启服务:
http://localhost:1083/view/index您可以在各种浏览器中配置使用SSH-Tunnel提供的代理服务:
您也可以使用浏览器扩展来方便地切换代理设置:
您可以运行多个SSH-Tunnel实例,连接到不同的服务器或使用不同的配置。这在以下情况下特别有用:
# 实例1
./ssh-tunnel -s server1 -l 127.0.0.1:1081 -http.local.address 127.0.0.1:1082 -admin.address 127.0.0.1:1083
# 实例2
./ssh-tunnel -s server2 -l 127.0.0.1:2081 -http.local.address 127.0.0.1:2082 -admin.address 127.0.0.1:2083
对于Windows服务,您需要:
# 在C:\ssh-tunnel1目录安装第一个服务
C:\ssh-tunnel1\ssh-tunnel-svc.exe install --config=C:\ssh-tunnel1\.ssh-tunnel\config.properties
# 在C:\ssh-tunnel2目录安装第二个服务
C:\ssh-tunnel2\ssh-tunnel-svc.exe install --name "SSHTunnelService2" --config=C:\ssh-tunnel2\.ssh-tunnel\config.properties
对于MacOS,创建多个不同名称的plist文件:
# 第一个实例
/Library/LaunchDaemons/com.idefav.ssh-tunnel1.plist
# 第二个实例
/Library/LaunchDaemons/com.idefav.ssh-tunnel2.plist
是的,SSH-Tunnel可以与许多其他工具和服务集成:
配置Git使用SSH-Tunnel:
# 使用HTTP代理
git config --global http.proxy http://127.0.0.1:1082
# 使用SOCKS5代理
git config --global http.proxy socks5://127.0.0.1:1081
设置Linux/MacOS命令行代理环境变量:
# HTTP代理
export http_proxy=http://127.0.0.1:1082
export https_proxy=http://127.0.0.1:1082
# SOCKS5代理
export ALL_PROXY=socks5://127.0.0.1:1081
Windows命令行代理:
set http_proxy=http://127.0.0.1:1082
set https_proxy=http://127.0.0.1:1082