Read more

SSH add/remove port forwarding to active session

Marc Dierig
June 23, 2023Software engineer at makandra GmbH

It is possible to manipulate the forwarded ports of an established interactive SSH session.
This is done by opening the command line with the escape character ~C. This will open a ssh> prompt. If it doesn't, make sure it's the first character in a line, i.e. press enter first.

You have following commands at your disposal

-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

Excerpt from man ssh, line 487

~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.  !command allows the user to
        execute a local command if the PermitLocalCommand option is
        enabled in ssh_config(5).  Basic help is available, using
        the -h option.
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot
Posted by Marc Dierig to makandra Operations (2023-06-23 17:34)