Break out of SSH session

Sometimes after I've established an SSH connection to an SSH server, I encounter a situation where the remote system isn't responding to keyboard input and I want to terminate the SSH session and return to a command prompt. E.g., often when I've connected to a Microsoft Windows system running SSH software from my Ubuntu Linux laptop, I find that I'm in a situation where after I've entered a command at the Windows system's command prompt the remote system no longer seems to be accepting keyboard input from the Linux system. Sometimes it seems to occur when I've mistyped a Windows command and the Windows system may be waiting for further input, but doesn't seem to accept what I type. In such cases, rather than close the Terminal tab on the Linux system to terminate the connection, which then requires me to open a new tab and establish a new SSH session, I'd prefer to break out of the current SSH session and return to the shell prompt on the Linux system where I can re-establish the SSH connection. In such cases, Ctrl-C, Ctrl-D, and Ctrl-Z don't help me.

But there is an escape sequence that will allow me to terminate the current SSH session. Hitting the three keys listed below will allow me to terminate the session.

↲ Enter, ~, .

I.e., hitting the Enter key then the tilde, aka "squiqqle" character, which is obtained by hitting the Shift key and then the key with ` and ~ on it, then the key with the period on it.

You can see the other escape sequences available to you in an SSH session by typing ~?, i.e., the tilde and then question mark key. They are shown below:

Supported escape sequences:
  ~.  - terminate connection (and any multiplexed sessions)
  ~B  - send a BREAK to the remote system
  ~C  - open a command line
  ~R  - Request rekey (SSH protocol 2 only)
  ~^Z - suspend ssh
  ~#  - list forwarded connections
  ~&  - background ssh (when waiting for connections to terminate)
  ~?  - this message
  ~~  - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)

You need to hit the Enter key before hitting the other keys, i.e., the escape sequences are only recognized after a newline. If you wish to return to what you were doing after viewing the above escape sequences by using ~?, simply hit the Enter key.

 

TechRabbit ad 300x250 newegg.com

Justdeals Daily Electronics Deals1x1 px