If you forgot to put in your string of -L and -R and -D port forwards with ssh: ie: ssh -L 54321:localhost:443 root@mysshserver.com . Dont worry, you can launch them while your in your ssh session (doing it live!). But only If you use “ssh” as your client (not sure if it will work with putty) you can do this.

SUMMARY: only possible with ssh program (not putty – maybe its possible with putty just not with regular options). From Man Page we see ~C gets us to ssh command mode. First Type SHIFT-~ (to get ssh to listen to special escaped ssh commands) and then SHIFT-c (to get the capital C, I do it without letting go of shift until after I press the C). This gets it into a special ssh command prompt that looks like this ssh> . Now type ? or help to see the format of the different commands you can type. And start stringing your -L and -R and -D commands. i.e. -L 54321:localhost:443  but it will look like this in the prompt ssh> -L 54321:localhost:443 (because ssh>  is the prompt so of course it will look like that). Here is the command:

To check out your list of port forwards. SHIFT-~ and then SHIFT-3 (to get the # key). This will list your port forwards like so (this one I used -L 30003:localhost:443 )

Now to cancel this port forward you would type SHIFT-~ and then SHIFT-c (to get the capital C) which gets you to the ssh prompt. Now type this to cancel  -KL 30003 of course you will see this because its a prompt  ssh> -KL 30003


NOTE: With default options I cant get putty to do this, after all putty client is not ssh client.

NOTE: with putty you can setup port forwards while your session is running, thru the GUI, but not with the keyboard.

NOTE: even though this doesnt work with putty, it will work with ssh program provided by cygwin (the regular openssh ssh client program)

NOTE: ~ is literally the tilde character. So to get ~C you press in SHIFT (dont let go) and hit ` (tick mark, which is the tilde when shift is held) and then c (which is the capital C with shift held. dur..)

A list of all of the ESCAPE CHARACTER options (From the FreeBSD ssh man page):

So when your in an ssh session press

~C and then you will see an ssh prompt ssh>  and then type your forwarding command per these rules (to list these rules type ?  enter)

So for example I want to locally forward 54321 on this local windows PC (using ssh in cygwin) to port 443 on the SSH server:

Type:

So that you see:

Then hit Enter and now you should have that port forward setup. So go to your browser and type “localhost:54321” and you will access the 443 webserver on the ssh server.

To cancel your prompt get back to the ssh prompt and type ssh> -KL 54321

Sidenote: if you specified the bind_address with your portfowards like so  ssh> -L localhost:54321:localhost:443 , then you will have to kill it like this  ssh> -KL localhost:54321 . Note I think by default (if you dont specify that bind_address) the bind interface is all interfaces  *:54321:localhost:443  (meaning all interfaces can connect to 54321).

Leave a Reply

Your email address will not be published. Required fields are marked *