Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I’m connecting to a server via SSH to send a message to a socket server using a command like:

ssh -p 5566

After the connection is established and I write the message and send it I can’t exit the text mode. I’m only allowed to enter more text and that’s it.

Is there a command or a key combination that allows me to return to command mode?

share|improve this question
The example you give has nothing to do with messages. You are connecting to a host with SSH to a non standard port. In most cases you will get a shell. If the server is configured to use a special texting program as a login shell you need to give us more details. – Matteo Aug 28 '12 at 15:26
what you call text mode and command mode, is unclear, as there are no such modes. so perhaps you should use screenshots to explain what you see and what you expect, and not try to use terms of your own making which sound great but have nothing to do with ssh. – barlop Aug 28 '12 at 15:29
Thank you for your answers! @Matteo I've implemented a channel socket server and i wanted to test it before implementing the client, but since i'm new to Linux, i didn't know that ssh can't be used like telnet in this case, because it simply has other purpose. Barlop, sorry for the ambiguous terms i have used, "text mode" something where you add text until you enter an escape character, "command mode"~= everything else after you enter the escape character. – Andreea Aug 29 '12 at 6:41
up vote 98 down vote accepted

Short answer: Type exit

If that doesn't work, however...

SSH Escape Character

Most SSH implementations implement an escape character for interactive sessions, similar to telnet's Ctrl-] combination. The default SSH escape character is ~, entered at the beginning of a line.

If you want to terminate an interactive OpenSSH session which is stuck and cannot be exited by entering exit or CtrlD into a shell on the remote side, you can enter ~ followed by a dot .. To be sure to enter the escape character at the beginning of an input line, you should press Enter first. So the following sequence will in most cases terminate an SSH session:


Other Escape Sequences

OpenSSH, for example, offers other escape sequences besides ~.. Entering ~? during a session should give you a list. Some examples:

  • ~ followed Ctrl-Z suspends the session,
  • ~& puts it directly into background,
  • ~# gives a list of forwarded connections in this session.
  • If you want to simply enter a tilde at the beginning of a line, you have to double it: ~~.

The escape character can be changed using the command line option -e. If you set the special value -e none, escaping is disabled and the session is fully transparent.

See also the OpenBSD man page on ssh (which is referenced from under the -e command line option

share|improve this answer
Why make it simple when you can have it uselessly complicated? – MariusMatutiae Jun 6 '14 at 12:14
@MariusMatutiae The OP asked for a case where there was no remote shell to enter exit or Ctrl-D, but just a listening process. I clearly stated that my solution is suited for a session which is stuck and cannot be exited. I tried to clarify this more, hope it is easier to see now. – Dubu Jun 10 '14 at 9:47
I was sceptical, but ~. without spaces was exactly what I needed, thanks! :) – Jamey Jun 25 '14 at 14:38
In swiss german keyboard layout, tilde is generated by pressing AltGr+^ (plus it's a blocking key). Because of this, it seems that the escape sequence doesn't work. Does anyone know how to type the default escape in swiss german? – Daniel Alder Dec 1 '14 at 12:14
@Dobu Found the reason why it didn't work before. If you already typed ~ in the same line (which easily happens if you are testing), the following ~. sequences are ignored. Had to press return first... – Daniel Alder May 20 '15 at 13:16

Do you want to exit the SSH shell?

You can type exit and hit Enter, or use Ctrl+D

share|improve this answer
"exit" helped me as ctrl+d not worked in VNC viewer...thanks – raj gupta Jun 10 '13 at 7:57
This doesn't work in cases where the machine freezed or disappeared or the application doesn't respond to any input – Daniel Alder May 20 '15 at 11:36

Just type exit or logout (then hit Enter of course) both will work.

share|improve this answer

You can write logout in the console line (and hit Enter of course).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.