Harsh but fair

Open source chicanery and the battle with my inner geek

Escape from Telnet

Posted by raetsel on August 12, 2007

Not the title of a 50s sci-fi novel but something I find I need to do at work now and again. Telnet is something of a deprecated method of connectivity because of its inherent lack of security. ( Anything transmitted over a telnet session is transmitted in the clear ). The preferred method of remote connectivity is usually ssh that will encrypt the traffic. However many devices like jet direct print server boxes only support telnet and indeed many of the Unix servers at work don’t have ssh installed. (Sshhh don’t tell the crackers).

So now and again I find I am telnetted (new verb) on to a system and then telnet to a device only for it to hang and I need to escape from the telnet session. Now as standard Ctrl + ] (^]) will get you to the telnet “command prompt” and from here you can type quit to end the hung session. However there is a snag when you have telnetted to one server and then to another server or device. The Ctrl + ] is actually interpreted by the first telnet connection and you end up escaping that one and severing your initial connection not the secondary one.

The reason for this is fairly obvious telnet inspects your keystrokes and passes them through to the remote connection, if it sees the escape sequence then it responds. Now when you telnet from a telnet session that first telnet inspects all your keystrokes before passing them on to the remote connection which is itself running telnet. (See diagram below).

Telnet Usage

So how do I get the second telnet session to see the Ctrl+] ? Well the trick is to press Ctrl+] to get to the command prompt of the first session and change the escape sequence of that session using the command “set escape” you need to choose a control sequence you won’t type for any other reason say Ctrl+[ or Ctrl+B then hit “enter” to return back to your connection.

At this point you can type Ctrl+] and the first telnet session will see this as a normal character sequence and pass it on to the remote connection (our second telnet session). The second telnet session will then to the escape sequence and give you the command prompt where you can type quit.

So now you are back are the first connection and you can do whatever work you want to do. You just have to remember if you need to escape from this session for some reason use your newly set escape sequence Ctrl+B or whatever.

About these ads

4 Responses to “Escape from Telnet”

  1. drj11 said

    And should you actually wish to transmit Ctrl-B (or whatever you set your escape to), for example to a distant emacs or somesuch, then you can use “send escape” from the telnet prompt that you get when you press the telnet escape key. This is a ludicrously inconconvenient way to send a single character, but it’s sometimes worth knowing.

    It’s worth googling for GLS’s telnet song too.

  2. Ah that’s a very handy little wheeze.

    In fact using that you can avoid the need to reset the escape key sequence in the first place. If you telnet to box A then telnet to box B then at that point you can press the standard Escape ^] which is interpreted by the first telnet (connected to box A ) and drops you to that prompt. From there do a “send escape” and that is sent to the second telnet (box B) and drop you to that prompt where you can type “quit” and drop that connection.

    I’d say that is a slightly neater and shorter solution and saves you having to remember what new escape key sequence you needed.

    Thanks David!

  3. […] in rsync – watch those spaces!Snmpd filling up /var/log/messagesLaptop Build: apt-get behind a proxyEscape from TelnetKDE4 Save Current Session – DBUS to the RescueSamba Shares, Spaces and fstab (With a bit of Octal […]

  4. Rsync said

    Rsync…

    […]Escape from Telnet « Harsh but fair[…]…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: