Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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'm using openssh on both client and server. I know I can run ssh -L or ssh -R to setup some port redirections over ssh. However, since they are command-line parameters, such redirections must be written before the connection is opened.

Can I setup port redirections on-the-fly using the command-line ssh client?

When I used the PuTTY ssh client, I could interactively setup a port redirection while a connection was already opened, without dropping nor reconnecting, thus I know it is technically possible.

share|improve this question
up vote 9 down vote accepted

If you're using the SSH command line, and you haven't switched the escape character feature off, then you can type ~C after a newline to open a mini-console on the ssh client. Then type -L port:host:port or -R port:host:port or -D port as you would on the command line to add a redirection, or -KR port to remove a redirection.

A more flexible method to set up redirections without redoing the authentication is to start the first ssh client as a master (-M or -o ControlMaster=auto) and subsequent clients as slaves (-S or -o ControlMaster=auto). The slaves tunnel through the connection established by the master. You may need to set ControlPath on the command line or in your ~/.ssh/config; see the description of the options in the ssh_config man page for more information.

share|improve this answer

Your Answer


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.