Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In an ssh session, one can start tunneling with the keystrokes ~C and entering (e.g.) -L80:localhost:80. However, is there any way to stop tunneling on that port (short of killing the process)?

share|improve this question
I doubt it but killing the process is as minor as a ctrl-c.unless i guess you ran it in the background, and you could then run ssh again but without the -L80:localhost:80 I suppose if you added -N then it stops the ssh shell from popping up then its raison d'etre would be for the -L and so there really wouldn't be any point in an option to stop listening,because it would have no other function.I think its raison d'etre is whatever it was set up to be with -L or without.maybe for it to be able to do different to that after would be bring up an unnecessary security consideration and complexity. – barlop Dec 16 '12 at 3:12
The point isn't that I don't know how to kill the process. It's that I need to keep it running, since I'm actively using that connection. – Yang Dec 16 '12 at 4:00
I only see two uses. a)shell b)tunneling. So you could create two connections. One for the shell(which I guess is the one you're "actively using". And one for the tunneling -L (with -N to specify no shell). Then you could kill the tunneling connection, and keep the shell connection. – barlop Dec 16 '12 at 4:04
@barlop Yes, of course if you have a separate process per tunnel, then you can get the effect you want by killing the process. And that is effectively what I do today. But my question is on whether you can stop the tunneling given the assumption that you do not want to kill the process. For instance if you accidentally start a tunnel on the same process. Effectively, is there a way to undo that? – Yang Dec 16 '12 at 5:47
I understand what you mean, I don't know of a way(only those workarounds which you already know/do). If you have no luck here, I suggest trying the ssh mailing list, or the newsgroup both those sources of support/expertise happen to be the ones mentioned/recommended in the ssh faq, so kind of official too.. i've seen is quite effective, I haven't seen the mailing list but it's probably good too. – barlop Dec 16 '12 at 8:05
up vote 4 down vote accepted

Excerpt from ssh(1) manpage:

 ~C      Open command line.  Currently this allows the addition of port
         forwardings using the -L, -R and -D options (see above).  It also
         allows the cancellation of existing port-forwardings with
         -KL[bind_address:]port for local, -KR[bind_address:]port for
         remote and -KD[bind_address:]port for dynamic port-forwardings.

So, ~C followed by -KL80 cancels the port forwarding in your example.

share|improve this answer
brilliant, that works(in my test at least). ssh escape sequences, who knew! Initially when I was trying it, I thought the tilda key or my finger, wasn't working. As when one types for example, ~? the tilda as an escape character, is treated such that it doesn't display on the first tap(but it is indeed there and should only be tapped once). I was getting confused too, tapping ~ till ~ appeared once, then tapping ?. Hitting ENTER and it failed. Copy/paste ~?, and it worked. and of course the ~C followed by the -KL.. worked too. – barlop Dec 16 '12 at 9:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .