0

As you can see I get error message when I try to create another tunnel listening on local port that is already used but the tunnel is created. Can I force ssh to not create tunnel on given port when there is another process that is using given port?

┌─[wakatana@~] [79 files, 89Mb]
└──> ps -elf | grep 'ssh -fN'
1 S wakatana     4263     1  0  80   0 - 10660 -      May02 ?        00:00:00 ssh -fN -L 5901:localhost:5901 root@MY.PUB.IP.ADDR
0 S wakatana     6340  4754  0  80   0 -  1959 -      00:22 pts/7    00:00:00 grep --color=auto ssh -fN

┌─[wakatana@~] [79 files, 89Mb]
└──> ssh -fN -L 5900:192.168.1.1:3389 root@MY.PUB.IP.ADDR
┌─[wakatana@~] [79 files, 89Mb]
└──> ps -elf | grep 'ssh -fN'
1 S wakatana     4263     1  0  80   0 - 10660 -      May02 ?        00:00:00 ssh -fN -L 5901:localhost:5901 root@MY.PUB.IP.ADDR
1 S wakatana     6371     1  0  80   0 - 10355 -      00:22 ?        00:00:00 ssh -fN -L 5900:192.168.1.1:3389 root@MY.PUB.IP.ADDR
0 S wakatana     6381  4754  0  80   0 -  1959 -      00:22 pts/7    00:00:00 grep --color=auto ssh -fN

┌─[wakatana@~] [79 files, 89Mb]
└──> ssh -fN -L 5900:192.168.1.3:3389 root@MY.PUB.IP.ADDR
bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 5900
Could not request local forwarding.
┌─[wakatana@~] [79 files, 89Mb]
└──> ps -elf | grep 'ssh -fN'
1 S wakatana     4263     1  0  80   0 - 10660 -      May02 ?        00:00:00 ssh -fN -L 5901:localhost:5901 root@MY.PUB.IP.ADDR
1 S wakatana     6371     1  0  80   0 - 10355 -      00:22 ?        00:00:00 ssh -fN -L 5900:192.168.1.1:3389 root@MY.PUB.IP.ADDR
1 S wakatana     6391     1  0  80   0 - 10355 -      00:23 ?        00:00:00 ssh -fN -L 5900:192.168.1.3:3389 root@MY.PUB.IP.ADDR
0 R wakatana     6401  4754  0  80   0 -  1958 -      00:23 pts/7    00:00:00 grep --color=auto ssh -fN
6
  • ssh is /already/ not creating the second tunnel - that's what the error messages 'cannot listen to port' and 'could not request local forwarding' mean. (after re-reading your question) I presume you want the second ssh process to terminate, rather than persist? – Daniel Lawson May 3 '15 at 2:41
  • If it's not creating second tunel then why there are two ssh processes listening on port 5900? – Wakan Tanka May 3 '15 at 8:22
  • There aren't two processes listening on that port. There are two processes with command lines that instruct them to listen on that port, however the bind() call for the second process failed. – Daniel Lawson May 3 '15 at 9:58
  • The one missleading thing is: why ssh process did not exit after bind failure? – Wakan Tanka May 3 '15 at 11:43
  • Why this implementation of SSH? – Wakan Tanka May 3 '15 at 16:27
2

I tried to think about how to tidy your question up, but don't have time. I can answer it for you: You need the 'ExitOnForwardFailure' option set to yes.

$ ssh -fN -o ExitOnForwardFailure=yes -L 5900:192.168.1.1:3389 root@MY.PUB.IP.ADDR
$ ssh -fN -o ExitOnForwardFailure=yes -L 5900:192.168.1.3:3389 root@MY.PUB.IP.ADDR 
bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 5900
Could not request local forwarding.
$ ps auwwx | grep ssh | grep 1111
daniel          94948   0.0  0.0  2461204    520   ??  Ss    2:56pm   0:00.00 ssh -Nf -o ExitOnForwardFailure=yes -L 5900:192.168.1.1:3389 MY.PUB.IP.ADDR

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.