Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

3 Answers 3

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 at 21:17
    
Cool, thanks for the uodate! –  Mbrevda Nov 21 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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