通过 SSH 暂停计算机后如何恢复终端?

通过 SSH 暂停计算机后如何恢复终端?

我经常通过 SSH 进入计算机,只是为了让它进入睡眠状态。问题是,当计算机进入睡眠状态时,它会保持 SSH 连接打开(似乎无限期地保持打开状态)。以下是发生的情况:

oli@bert:~$ ssh tank
oli@tank:~$ sudo pm-suspend
[sudo] password for oli:

我输入密码,点击Return然后它就挂了...直到我唤醒远程机器。

有什么方法可以强制本地断开连接,以便我可以恢复我的终端,而不必关闭它并启动另一个?

答案1

输入 SSH 转义代码!来自man ssh

ESCAPE CHARACTERS
 When a pseudo-terminal has been requested, ssh supports a number of
 functions through the use of an escape character.

 A single tilde character can be sent as ~~ or by following the tilde by a
 character other than those described below.  The escape character must
 always follow a newline to be interpreted as special.  The escape
 character can be changed in configuration files using the EscapeChar
 configuration directive or on the command line by the -e option.

 The supported escapes (assuming the default ‘~’) are:

 ~.      Disconnect.

 ~^Z     Background ssh.

 ~&      Background ssh at logout when waiting for forwarded connection /
         X11 sessions to terminate.

因此:按Enter~.

相关内容