前阵子因为要折腾 VPS 的缘故把博客暂时放在了 @likounin 童鞋的服务器上,不想最近他的服务器出了点问题,于是只能赶紧把 VPS 重新折腾回原样,然后把博客搬回来。
慌忙折腾之中遇到个问题:在 SSH 里卡住了,没法 Ctrl-C(因为这种按键会直接发给远端),该怎么正常退出?
想来也应该有个转义序列可以直接对 SSH 做操作……于是,那就是 ~。
SSH 到服务器后,确保之前按过一次回车,然后按
~?
于是就会列出一堆可用的转义序列,比如:
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.)
总之,要退出已经卡住的 SSH 程序,可以在按一次回车(见上面帮助信息的最后一行)之后,按下
~.
话说回来,转义字符也只是默认是这个 ~ 字符而已,如果不喜欢的话,ssh_config 文件中有一个选项叫 EscapeChar 可以修改转义字符。
以上。

