首页 > 解决方案 > 如何在后台启动批处理文件中运行 ssh 反向隧道?

问题描述

基本上我想在启动时写.bat文件,在后台做一个反向隧道

所以这些是我在批处理文件中尝试过但没有工作的东西

ssh -fN -o StrictHostKeyChecking=no -R port1:localhost:port2 user@ip 

ssh -f -o StrictHostKeyChecking=no -R port1:localhost:port2 user@ip 


start /min cmd.exe /C "ssh -fN -o StrictHostKeyChecking=no -R port1:localhost:port2 user@ip"   

start /min cmd.exe /C "ssh -f -o StrictHostKeyChecking=no -R port1:localhost:port2 user@ip"   


start /min cmd.exe /C "ssh -o StrictHostKeyChecking=no -R port1:localhost:port2 user@ip"   

当我不包括选项 N 并说 -f 时,它不起作用并且我无法从另一端连接

当我说 -fN 时,奇怪的是(有或没有 /min)会产生一个新的空 cmd shell,即使我手动关闭它,我仍然可以连接!尝试在超时后杀死 cmd.exe 以自动关闭它,但这没有用

但必须有一种方法,我如何在批处理文件中发送反向 ssh 隧道而不让用户注意到它?

标签: windowsbatch-filesshssh-tunneltunnel

解决方案


我认为您可以尝试编写一个批处理脚本来在启动时运行该命令。您可以参考https://ss64.com/nt/start.html了解更多信息。我在其中找到了一个/B参数,可以解决您的问题。


推荐阅读