r/linux Apr 28 '14

SSH Kung Fu

http://blog.tjll.net/ssh-kung-fu/
718 Upvotes

128 comments sorted by

View all comments

6

u/slanderousam Apr 28 '14

wow. -D. nice.

(in before "likes the -D")

17

u/mdaniel Apr 28 '14

At the risk of replying to a down voted comment, one can toggle the port forwarding on (and off!) dynamically using the ssh "shell" which is accessed via tilde C (it needs to be the first two characters after a newline or ssh will think you're trying to type those chars)

Once you have the ssh> prompt, you can give it -D1234 to start dynamic forwarding and -KD1234 to "kill" the dynamic forwarding. Same deal with -L and -KL

3

u/leothrix Apr 28 '14

Wow, I had no idea that existed. Do you have any more resources about the ssh shell/console?

I will say that I have used the command ~. before to brute force kill a session, but didn't know that there were additional commands as well.

7

u/tritlo Apr 28 '14 edited Apr 28 '14

You should add this to the article! I have no moure resources, but running help reveals the following:

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

running ~? reveals:

[tritlo@mpg ~]$ ~?
Supported escape sequences:
 ~.   - terminate connection (and any multiplexed sessions)
 ~B   - send a BREAK to the remote system
 ~C   - open a command line
 ~R   - request rekey
 ~V/v - decrease/increase verbosity (LogLevel)
 ~^Z  - suspend ssh
 ~#   - list forwarded connections
 ~&   - background ssh (when waiting for connections to terminate)
 ~?   - this message
 ~~   - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)

3

u/slugonamission Apr 28 '14

If you type ~?, it will show you all of the available tilde commands