
The text adventure game of exiting a Telnet session - Mojah
https://ma.ttias.be/exit-telnet-session/
======
cmrdporcupine
A story about telnet escape...

Back in the early 90s the local university used to have a free dial-up that
you'd connect to via modem and then could telnet anywhere. You didn't need to
be a student or anything. As a teenager I used this to connect to various
shell accounts I had around, and to various MUDs. (This was in the pre-ISP
days -- there was nobody in my area offering dial-up Internet at all.)

At some point they pulled this and made it for students only. But they had a
dial-up gopher service for campus information and library access that was
actually a telnet session to a gopher client on a SunOS machine somewhere.

But they didn't disable the telnet escape character.

So for a few months back then the way I got Internet access was to dial into
the gopher client, hit ^], close the session to the gopher client, and open to
anywhere else I chose. Eventually they closed this hole, too, but it was
glorious for a while.

~~~
mds
Oh man, I have the same memory. Back in ‘92 or ‘93, in addition to the “^]”
telnet trick, our local dial up gopher could launch vi sessions for sending
emails which they hadn’t thought to lock down to prevent it from executing
“sh”. Poking around in those university systems was my first exposure to Unix
and I’d say pretty directly influenced my career path.

So, thanks telnet!

~~~
hinkley
My roommate volunteered as the webmaster for a non-profit, and they had a
little tool that gave him vi access but no shell access.

Apache won't serve certain files unless the permissions are just so, and he
could not get them to fix them _or_ give him a shell to do it himself. So he
couldn't do his job.

I ended up telling him about the shell escape trick.

------
derefr
One key thing to know, is that typing a character with the Control key held
into a CLI session (real or PTY) causes the TTY driver to receive an octet
that looks like that letter ANDed with ~0x40. In other words—referencing an
ASCII table—you emit NUL by typing ^@, BEL by typing ^G, and so forth. ^H is
literally BS (the ASCII backspace character.)

Another key thing to know, is that old pre-PS/2 keyboards actually emit these
ASCII symbols, or something like them, directly, when you hit the appropriate
key; and also do the appropriate Control-masking in hardware. When you hit the
Backspace key on an IBM Model-M keyboard, it's sending 0x08 down the line.
When you hit Control+H, it's _also_ sending 0x08 down the line. The computer
receiving these can't tell the difference (and, in fact, does not receive
KeyDown/KeyUp signals for the Control key. It's not a "key" as such.)

And so, what's happening with the author's "cheat sheet", is that there's some
particular key on these keyboards that has 0x5D ']' as its scancode; and,
despite modern keyboards no longer doing Control-masking in hardware, the
author's Terminal emulator is doing it in software, translating the key-chord
of "the key with scancode 0x5D" \+ "control being held" into "the ASCII symbol
0x1D" (that's GS/Group Separator, for those wondering) and emitting that octet
through the TTY driver into the telnet client, which receives it and treats it
indistinguishably from someone who had typed Control+] on a US 101-key
keyboard.

------
inetknght
Not going to lie: when I discovered that `^` means _control_ and that `^]`
means _control-]_, I suddenly started making sense of a ton of
manpages^H^H^H^H^H^H^H^Hdocumentation.

Then the `tmux` dude goes on and uses `C` instead of `^` [0]. God that was
hard to figure out. But it gets worse: he continues to describe it as `C` even
when he's not actually meaning _control_. No, that's just the _default_. He
actually means `C` to mean whatever was bound to the configured "meta
control". Uhh, at least, that's my understanding of it right now.

Tmux author (if you read this): I still haven't figured out why your software
can't redraw lines. I'm continuously seeing garbled nonsense on the session
from software clearing a line but tmux not actually clearing that line. `htop`
works and looks great outside of tmux but inside of it? Oh god I can't read
anything at all because it's all garbled.

But yeah, after learning that `^` means "press control", getting out of Telnet
was eas....oh man I'm stuck in telnet stil.. Halp

[0]:
[https://github.com/tmux/tmux/wiki/FAQ](https://github.com/tmux/tmux/wiki/FAQ)

~~~
chin7an
As far as I can tell, emacs[0] denoted control as 'C' first. The tmux docs
most likely follow that trend. I'm only starting to learn emacs, so haven't
yet come across any key combos that require a capital letter 'C' preceded by
Ctrl. Will be interesting to see how that's represented.

[0]:
[https://www.gnu.org/software/emacs/manual/html_node/emacs/Ke...](https://www.gnu.org/software/emacs/manual/html_node/emacs/Keys.html#Keys)

~~~
Filligree
Ctrl is always a modifier.

So "C" is the letter C, "C-x" is ctrl-x, "C-c" is Ctrl-c, and there's no
ambiguity. You can't bind anything to Ctrl on its own.

~~~
anthk
"xev" differs. And xmodmap.

~~~
Filligree
Fair. I was talking specifically about emacs.

------
rcfox
That reminds me of the classic Bash.org quote about vi:
[http://bash.org/?795779](http://bash.org/?795779)

~~~
taneq
Or this one that came up recently here: [https://github.com/hakluke/how-to-
exit-vim/blob/master/READM...](https://github.com/hakluke/how-to-exit-
vim/blob/master/README.md)

~~~
wolco
The Jeffrey Way was very funny.

------
stewartm
Getting out of telnet? Mere bagatelle compared to trying to get out of `ed`
for the first time. At least Telnet attempts to tell you what to do.

The defacto ed tutorial exactly predicts/describes my first encounter:

[https://sanctum.geek.nz/arabesque/actually-using-
ed/](https://sanctum.geek.nz/arabesque/actually-using-ed/)

~~~
twic
Let's look at a typical novice's session with the mighty ed:

    
    
      golem$ ed
      
      ?
      help
      ?
      ?
      ?
      quit
      ?
      exit
      ?
      bye
      ?
      hello?
      ?
      eat flaming death
      ?
      ^C
      ?
      ^C
      ?
      ^D
      ?
    

Note the consistent user interface and error reportage. Ed is generous enough
to flag errors, yet prudent enough not to overwhelm the novice with verbosity.

\-- [https://www.gnu.org/fun/jokes/ed-
msg.en.html](https://www.gnu.org/fun/jokes/ed-msg.en.html)

~~~
stewartm
:) Had not spotted the humour section on gnu.org before.

From the same site, the source code of ed:

while :;do read x;echo \?;done

\--
[https://www.gnu.org/fun/jokes/ed.html](https://www.gnu.org/fun/jokes/ed.html)

------
kens
What's the history of using ^ to indicate a control character? Wikipedia
([https://en.wikipedia.org/wiki/Caret_notation](https://en.wikipedia.org/wiki/Caret_notation))
didn't provide any history.

~~~
simonh
I suspect it may be down to the use of the Caret key on typewriters and
teleprinters as a modifier on other characters. Often the caret was a ‘dead
key’ that did not advance the carriage, so you could then type another
character in the same location, which would be accented by the caret mark. If
you wanted a caret by itself you had to then press the space bar. The control
key is also used to modify the meaning of another key, and does not advance
the cursor.

------
salmo
Don’t use Telnet to check a port. It’s overkill that puts you in the situation
where you have to force it to abort because the server doesn’t speak telnet.

Netcat (based on the old Hobbit code) or nmap’s ncat are pretty universally
installed. It just opens a socket and lets you type away until EOF (^D). Or
you can just do “nc -v host port < /dev/null” (or just do ”-z” for non-ncat).
Hilariously my phone doesn’t have backticks for me to denote those as
commands.

~~~
m463
You have a point - you should use the best tool for the job.

It's just that telnet seems to be more universally installed in my experience.
(arch linux for example)

------
heffer
I feel the pain. When you are switching platforms from anything to a Mac for
the first time and your Mac Book comes with, say, a German keyboard, you will
find yourself googling where to find all the different brackets you need for
coding first thing as they are not printed on the keys. Judging from this
article this seems to be similar for many other keyboard layouts as well.

~~~
reaperducer
I just did an image search, and you're right — no brackets printed on the
keyboard.

I find this interesting, because back in the 90's I happened to be in Austria
and I bought a German keyboard for the sole reason that it had all of the
brackets on it, and the US keyboard I was using at the time didn't.

Keyboards can be so random. I wonder what goes into these kinds of decisions
amongst keyboard designers. (I know there's an ISO committee for this, but we
all know "standard" ≠ "best")

~~~
heffer
Fun fact: If you use muscle memory, coming from a German non-Mac keyboard
layout to a Mac keyboard layout you'll end up constantly closing applications.
The combination for @ on non-Mac keyboards is AltGr + Q and on Mac is Alt+L.
Now if you use your left hand to type @ the AltGr key is roughly where the
Command key is on an Apple keyboard. Thus you end up pressing Command + Q:
quit. It's great fun when adding additional recipients to a lengthy email you
are writing. Thank god for auto save and terminal buffers.

------
peter_d_sherman
Excerpt:

"My keyboard doesn’t have a ] sign on it."

Which leads to the following question (for future language designers)...

 _How do developers in foreign countries, using keyboards with no '[' or ']'
symbols on them, type square brackets '[]' for array notation, when they are
using arrays, in any programming language that requires brackets for array
notation?_

?

~~~
ASalazarMX
I share with you the pain of writing a bash script with a Spanish keyboard. It
has _three_ types of ticks (`'´).

The first and last are actually diacritics, so you have to press once, then
press the space bar. We don't even have back diacritics in Spanish.

~~~
GranPC
Catalan does have grave accents, and they use the same keyboard layout, so I
guess it makes some sense.

~~~
ASalazarMX
I assumed it was so they could write other European languages, but being
Mexican, I didn't consider Catalan needs grave accents. Makes sense, indeed.

------
dekhn
I wrote a MUD client for VMS because telnet in VMS was so broken. However, I
never documented the exit command (it was "Control-Y", not /quit or /exit. I
got email for years saying it was impossible to quit MUDding. Eventually I
just told people it was a feature.

------
skizm
The square bracket buttons seem like fairly fundamental characters to relegate
to very non-clear three-button shortcut that isn't even labeled on a keyboard.
I also don't see curly braces? Seems like an impractical keyboard layout, no?

~~~
Symbiote
For 99% of people, []{} are obscure mathematical symbols with little purpose
in daily life.

Many English-keyboard-owners can't type "6°C" correctly, or "6000cm³", so I
can't say Belgium's standard is _worse_.

~~~
hinkley
I was so happy to figure out 23°C on OS X, but ³ still stymies me.

~~~
Symbiote
I type them with the Compose key on Linux.

° is Compose, o, o.

³ is Compose, ^, 3.

€ is Compose, C, =.

— is Compose, -, -, -.

Ê is Compose, ^, E.

There are hundreds of reasonably guessable combinations.

------
sebazzz
Does anyone actually use a Dutch keyboard? It is something from Belgium? In
the Netherlands, where I lived my whole life, I've never seen a Dutch
keyboard. I've only seen US-English QWERTY keyboards.

~~~
Insanity
Azerty is actually more of a French layout than a Dutch layout. Keeping in
mind Belgium has three official languages (Dutch, French and German).

Azerty is pretty much the default in the non-IT world in Belgium. But, as for
software engineering, everywhere I worked though they asked if I wanted qwerty
or azerty layout on my machines.

I'd also recommend switching to qwerty as it's just more natural for
programming than azerty. Plus I got up to speed (~130wpm) after just a few
weeks of using it, so it's not a huge effort either.

------
Symbiote
This seems to be specific to Mac.

On Linux, when I remap the keyboard to Belgian (setxkbmap be), typing ] is
done with AltGr+the-key-two-to-the-right-of-P. At least on PC keyboards, ] is
printed on this key, on the right as is usual for AltGr combinations. Exiting
telnet is done with Control+AltGr+the-key-two-to-the-right-of-P.

When I set it to Danish, typing ] is done with AltGr+9, and exiting telnet is
done with Control+AltGr+9. ] is also printed on this key.

Why is Mac confusingly different?

For testing:

    
    
      telnet towel.blinkenlights.nl
    

Edit: if you think this is _not_ a Mac-only issue, please elaborate...

------
IshKebab
I wonder how people would complain if someone tried to fix this...

Edit: Here's the code: [https://github.com/marado/netkit-
telnet/blob/3f352877ee28cc4...](https://github.com/marado/netkit-
telnet/blob/3f352877ee28cc4335c3ab496ae95dd26dfe57ea/netkit-
telnet-0.17/telnet/commands.cc#L301)

But it seems to have been basically abandoned so I have no idea how you get
this into Debian.

------
leoc
Shout out to my Ctrl-^ people, or is that ^^? Not today, DNS.

------
stickfigure
The lesson here is that if you want to do programming-type work, use an
English-friendly keyboard. Which should make sense because most popular
programming languages are written in English (and 7-bit ascii to boot).

Either that or Belgians need a modernized keyboard with easy keys for popular
programming language chars.

~~~
djsumdog
I was surprised so many international keyboards don't have brackets! Do
software engineers in those language just remap those to accessible keys? It
would be super annoying to use one keyboard at home and a totally different
layout at work.

~~~
blensor
Just as I press Shift + letter to start a noun I use AltGr + 8 to start an
array. Not really much of a hassle.

------
jks
On many keyboards, ^] can be typed with ctrl-5. Also, ctrl-2 is ^@ (NUL),
ctrl-3 is ^[ (ESC), ctrl-4 is ^\, ctrl-6 is ^^ and ctrl-7 is ^_, all of which
can be hard to type on national layouts. Except for ^@, these correspond to
the last digit of the character code in octal: ^[ is 033 etc.

~~~
JdeBP
The thing to remember is that it is "on several _keyboard layouts_ " not "on
many keyboards". The actual keyboards themselves are completely agnostic as to
what the chords mean.

------
gpvos
_> Dutch, Belgian: ctrl + $_

Should be "Dutch (Belgian)" or "Belgian Dutch". In the Netherlands, no one has
such a keyboard, or any AZERTY keyboard for that matter (apart from the
occasional imported Belgian or French person), it's almost entirely US
keyboards.

------
ape4
It would actually be cool if somebody posted a patch to improve this. For
example when you start it could say "enter the key sequence you want to enter
to exit". Or it could adapt to different languages. Or just say "control-]"

------
silversides
I never remember (old habits) but you can use netcat for testing open ports.
(nc -z <host> <port>)

Apple for example doesn't include telnet by default anymore as it's considered
insecure so I end up brew install inetutils on my machines.

------
alejohausner
On UNIX/Linux/macos, control-Z will suspend the current process. But that gets
passed through telnet, and doesn't suspend telnet itself. Sooo....

Tilde, control-Z will do the trick: suspend the telnet process. Then

kill %1

kills the suspended telnet process.

------
shaggie76
Wait until you get to the software flow-control level (ctrl+s / ctrl+q).

------
derpsabert
One of the many reasons why SSH is superior. Hit ~. and you're out.

~~~
ASalazarMX
I just use the gold old ^D in an empty prompt.

[https://en.wikipedia.org/wiki/End-of-
Transmission_character#...](https://en.wikipedia.org/wiki/End-of-
Transmission_character#Meaning_in_Unix)

~~~
derefr
That's how you _gracefully shut down_ an SSH session, with the socket close
initiated from the remote end (where the shell is running.)

\n~. is for gracefully exiting a _stuck /hung_ SSH session (e.g. one where the
remote isn't responding to input) without force-killing the SSH client itself
(which might do bad things to the process group it lives in.)

------
Insanity
I'm Belgian as well, I'm really happy I eventually just made the switch to an
ANSI QWERTY keyboard. Azerty is not even that useful in Dutch anyway.

------
kazinator
^] is also the Vim command for chasing a tag (jumping to the location where
the identifier under the cursor is defined, perhaps in another file).

------
reaperducer
Since he's having this difficulty on a Mac, I wonder if enabling the "Show
Keyboard Viewer" option would have helped him.

------
slumdev
This is bizarre. I understand that not all keyboards are made the same, but
why would a technical person not have a keyboard with square brackets? Perhaps
one keyboard for writing volumes of text in his native language and another
keyboard for doing technical work?

The French language doesn't use the standard quotation mark to indicate
dialogue, but I would still expect a French programmer to have a keyboard
capable of producing one.

~~~
Symbiote
That sounds ridiculously inconvenient.

" and ' are on the standard French (and Belgian) keyboards.

In general on European keyboards, letters like ê, å, ç, ñ, ß are more useful,
so some of the punctuation only of interest to programmers and mathematicians
([], {}, ^, #, |, \, `, ~, _) is accessed using the AltGr (right alt) key.

Usually, the AltGr symbol is printed on the bottom right of the key
(Shift+AltGr symbols on the top right). Sometimes only some of these keys are
printed -- typical British keyboards print € on the 4 key, but not á, é etc --
although (of course!) they still work.

------
egdod
Just switch to a different terminal and kill the process.

------
ainiriand
tl:dr; He uses a keyboard without that escape symbol.

~~~
gtufano
Yeah, as literally anyone but who's using US or UK keyboards. :)

~~~
ainiriand
My point is that if you work with computers then probably is a good idea. Most
special symbol usage is because of that and escape sequences are derived from
those keyboards.

~~~
ASalazarMX
Next you will suggest we discard the 8th bit of ASCII text files.

And no, using the multinational US keyboard layout makes it even worse, it's
not designed for daily multilingual use.

------
dudus
That's what the reset button on old computers was for.

In all seriousness can't you just Ctrl+C or Ctrl+Z and kill the process
instead? Maybe there's something that prevents this that I don't remember, my
shell game is rusty.

~~~
syntheticnature
No, you can't, because telnet occupied the position SSH now does of remote
connection to a shell on another machine. Your Ctrl+Z or Ctrl+C gets passed
right through to control that remote machine, assuming you have a proper
telnet server on the other side that negotiated the appropriate options.

------
blensor
I don't know what the fuzz is all about, any sane person would open a
different console an just 'killall telnet'

Obviously this is a joke, but I have to admit that's usually my go to solution
for those rare cases where I need to actually use telnet (to some tcp socket
for debugging).

------
SQueeeeeL
Hasn't the "]" key been standard on keyboards for about 50 years...

~~~
djsumdog
Did you not read the article? Keyboards can be very different depending on
your region and language. The author shows a picture of an AZERTY keyboard.
Even ISO layouts can vary per country/language. That's why macOS asks you to
hit the keys to the left/right of the shift keys in an attempt to lookup your
keyboard layout.

~~~
AnIdiotOnTheNet
Since practically all keyboards are USB these days, one wonders why there
isn't a standard to have the keyboard just report its layout and language and
whatnot to the OS.

~~~
Symbiote
Because the keyboard electronics is the same, the difference is what's printed
on the plastic keycaps.

~~~
derefr
So? Monitor electronics (the panel) are the same, but the EDID chip in a
monitor still describes not only things about the panel, but about the monitor
itself, like its orientation or factory color-calibration, and in fact the
make and model of the monitor. Why not have such a chip in other peripherals?
They're not expensive. Many keyboards already have flash for firmware updates
or remembering F13-F24 binds.

~~~
JdeBP
That is not an analogous situation. Keyboard layouts are _entirely_ a software
thing. Modern keyboards have zero knowledge of keyboard layouts. Their
communications protocol does not deal in keyboard layouts. They effectively
speak entirely in terms of ISO 9995-1 key positions and a big bitmap.

* [https://news.ycombinator.com/item?id=21915931](https://news.ycombinator.com/item?id=21915931)

~~~
derefr
_Entirely_ a software thing? Seems like ISO 9995 and its extensions don't
specify anything about the top row of the keyboard (Escape, F1-F24,
PrintScreen/ScrollLock/Pause, etc.)

I know that "media keys" (e.g. a Calculator button) aren't actually keys but
another kind of USB HID device hanging out on the keyboard like a Touchpoint
mouse; but F1-F12 keys really are _keys_ , events sent from the same device
that sends regular keysyms. Are they just random non-positional codes hiding
out outside the ISO 9995 reserved range?

~~~
JdeBP
Yes, entirely. Function keys are not different to the others, and constitute
row K. Nor are "media" keys, which are just more keys. Apart from one key,
[Fn], they are _all_ just bits in a giant bitmap, indexed by USB HID usage and
(usually but not necessarily) partly encoded as an inverted array, on the
wire. The keyboard layouts, in software on the host, define the meanings for
all of them.

