SSH Escape Sequences - shawfdong/hyades GitHub Wiki

When a pseudo-terminal has been requested by the OpenSSH SSH client, ssh supports a number of functions through the use of an escape character. The escape character must always follow a newline to be interpreted as special. The default escape character is ~(tilde); but it can be can be changed in configuration files using the EscapeChar configuration directive or on the command line by the -e option.

$ ~?
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
 ~V/v - decrease/increase verbosity (LogLevel)
 ~^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.)

We can use tilde-period (~.) to close an unresponsive session.

BREAK is useful for various things, usually getting back to a terminal server console or getting the attention of network equipment[1].

The command line is used to request or cancel port forwarding on the fly, which can be very handy in a lot of scenarios, including VNC.

$ ~C
ssh> ?
Commands:
      -L[bind_address:]port:host:hostport    Request local forward
      -R[bind_address:]port:host:hostport    Request remote forward
      -D[bind_address:]port                  Request dynamic forward
      -KL[bind_address:]port                 Cancel local forward
      -KR[bind_address:]port                 Cancel remote forward
      -KD[bind_address:]port                 Cancel dynamic forward

One may never have to rekey a SSH session, as SSH protocol version 2 does it automatically after a certain amount of data has been transferred.

Suspending SSH via tilde-Ctrl-Z is handy from time to time, especially when you’re on the console of a machine that doesn’t have screen or some other multiplexor on it (or you forgot to start one). No matter how many SSH hops you are using to reach a particular remote machine, tilde-Ctrl-Z (~^Z ) will suspend the SSH session from the local machine to the first remotely connected machine.

user@local:~$ ssh example.com
[user@example ~]$ ~^Z [suspend ssh]

[1]+  Stopped                 ssh example.com
user@local:~$ fg
ssh example.com

[user@example ~]$

If you, however, want to suspend the second connection in a chain of more than one SSH session, enter ~~^Z instead; and so forth.

References

  1. ^ Changing the break character in Cisco IOS
⚠️ **GitHub.com Fallback** ⚠️