1. Press Ctrl-] (i.e. with one finger press and hold one of the Ctrl keys, then with another finger press the ] key):
2. Then if the telnet prompt appears, type close or quit or logout depending on which version of telnet you’re using.
Telnet to host myhost on port 20123:
$ telnet myhost 20123
Connected to myhost.
Escape character is '^['.