Home > Uncategorized > SSH Escape Sequences

SSH Escape Sequences

May 5th, 2009 grady

Yes, SSH has an escape sequence, much like telnet’s strl-] sequence. Remember those times when you, say, restart a daemon, go to log out of the server, but are left hanging? SSH escape sequence!

It’s tunable in /etc/ssh/ssh_config on the client-side, and of course in your ~/.ssh/config, but by default, the EscapeChar is the ~ key. So, if you ssh into a box. and type:
~?
 You’ll be presented with this list:

                Supported escape sequences:
                ~. – terminate connection
                ~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 can use ~. to kill the connection… or ~^Z to suspend it.

A particularly interesting one is the command line option, or “~C”. With that, you can get an ssh command line, with the following options:

  • -Lport:host:hostport    Request local forward
  • -Rport:host:hostport    Request remote forward
  • -KRhostport             Cancel remote forward

 That is, you can forward ports using your existing SSH connection, rather than starting up a new one. Cool!
 Another helpful way out of “locked” terminals is screen’s ctrl-a ctrl-k

Categories: Uncategorized Tags:
Comments are closed.