Knowing if a remote port forward was successful?

故事扮演 提交于 2019-12-04 03:39:44

问题


I am trying to setup some reverse ssh tunnels so I can access my home network by bouncing off some server with a public IP.

When I run this command: ssh -R :[port_XX]:localhost:22 some_user@my_server

Even if "port_XX" is in use, it will still make a successful ssh connection to "my_server".

If I am running this command directly, I can see the problem when it gives me a warning: "Warning: remote port forwarding failed for listen port [port_XX]"

However, I am starting this ssh session inside a screen session using a cron job.

How can I programmatically check if the remote port forwarding was successful?

The screen session can be checked with "screen -ls", the ssh session is also easily checked, but the remote port forwarding...?

(Please let me know if this question is not clear enough! I've done my research but haven't found a simple solution.)


回答1:


Try adding -o ExitOnForwardFailure=yes

The full command will be something like:

ssh -N -R [port_XX]:localhost:22 -o ExitOnForwardFailure=yes user@host

(-N is useful to just forward port, without opening a remote shell; you can also add -f to send process in background, no need if you are running under screen, though..)



来源:https://stackoverflow.com/questions/8514040/knowing-if-a-remote-port-forward-was-successful

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!