Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

1 Answer 1

up vote 4 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

 
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.