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

I can forward local ports using the command below

ssh> help
Commands:
      -L[bind_address:]port:host:hostport    Request local forward
      -R[bind_address:]port:host:hostport    Request remote forward
      -KR[bind_address:]port                 Cancel remote forward

ssh> -L 8080:localhost:8080
Forwarding port.

But how to cancel that port forward? I see the -KR for cancel remote forwards but there does not appear to be a -KL to cancel my local forward.

Asking for another forward on the same port (hoping to override the old one) gives this message

ssh> -L 8080:localhost:8081
bind: Address already in use
channel_setup_fwd_listener: cannot listen to port: 10101
share|improve this question
up vote 2 down vote accepted

with more recent versions of (open)ssh, there's an escape command to cancel local forwards as well:

ssh> help
Commands:
      -L[bind_address:]port:host:hostport    Request local forward
      -R[bind_address:]port:host:hostport    Request remote forward
      -D[bind_address:]port                  Request dynamic forward
      -KL[bind_address:]port                 Cancel local forward
      -KR[bind_address:]port                 Cancel remote forward
      -KD[bind_address:]port                 Cancel dynamic forward
share|improve this answer

There seems to be no way other than to exit the connection and start over. I'd love to be proven wrong...

share|improve this answer
    
Changed accepted answer due to updates in openssh – arcyqwerty Nov 20 '14 at 21:17
    
Cool, thanks for the uodate! – Mbrevda Nov 21 '14 at 4:55

There's no simple way to do it on the command-line.

You can find the PID:

$ ps x | grep ssh
 1234 ?        Ss     0:00 ssh -f -N -L 8080:localhost:8080 remotehost

And then kill the process:

$ kill 1234
share|improve this answer

You must log in to answer this question.

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