Geekblok

B10m, BOK, Joffie - old geeks on a blog

Entries Comments



Ssh tips and tricks, part 3

23 October, 2007 (20:38) | guides, technical | By: Joffie

For the third part in the guide, I’ll show the use of the escape_char and where it can come in handy. The default escape character in a openssh session is the tilde: ~. This might not be the best escape character together with your own keyboard layout. On some setups you must also use the space to get the tilde be a real tilde. Just test this in a xterm what you need to do to see an actual tilde. Otherwise, use the -e escape_char option, for example ssh -e '&' joffie.example.net.

After you have logged into the joffie.example.net machine, you can use the keystrokes & and . (dot), to close the connection. But there is more.


If you, for example also use the LocalForward from the previous guide, you can list the forward connections via & and #:

bq.
&#

The following connections are open:

#4 client-session (t4 r0 i0/0 o0/0 fd 8/9 cfd -1)

#6 direct-tcpip: listening port 5801 for localhost port 5801, connect from 127.0.0.1 port 53906 (t4 r2 i3/0 o1/30086 fd 12/12 cfd -1)

#7 direct-tcpip: listening port 5901 for localhost port 5901, connect from 127.0.0.1 port 57115 (t4 r3 i0/0 o0/0 fd 13/13 cfd -1)

As you can see I forwarded a vnc session in this session (ports 5801 and 5901). Mind that the escape char needs to be the first character on a line to be recognized.

You can also use the escape char in case you have forgotten that you wanted to setup a LocalForward (or a reverse tunnel, but I’ll get into that in a later guide) when you logged in. Imagine that you also want to localforward port 6666 to port 80 of b10m.example.net. Just open a commandline via & + C. This opens a small shell that has its own help. Just type -h:

bq.
ssh> -h

Commands:

-Lport:host:hostport Request local forward

-Rport:host:hostport Request remote forward

-KRhostport Cancel remote forward

After the help your command session wil exit, so you need to reopen it with a & + C and type:

bq. ssh> -L6666:b10m.example.net:80
Forwarding port.

And you’ll be back in the session with the new port forwarded and are able to browse to http://localhost:6666 to connect to http://b10m.example.net/. You can check that the localforward is there with the &#.

The ssh configuration file keyword of this guide was EscapeChar.

Comments

Comment from Blom
Time: October 24, 2007, 9:17 am

Awesome guide(s). Yet more new trickery I can and will use!

Write a comment





Preview: