SSH 会话暂停时关闭

SSH 会话暂停时关闭

我在远程主机上启动 ssh 会话并在远程主机上执行脚本。该脚本是一个更改远程 IP 的更新脚本。

现在我的本地 bash 脚本挂在线上,并显示以下命令:

ssh root@ip'/execute/this/script/test.sh/'…

我可以在 3 秒后关闭此会话吗?远程主机使用此脚本重新启动并获取新的 IP。

答案1

因此,您要做的就是按 [Enter] 键,然后按 ~..

  $ ~.
  $ Connection to xyz.com closed.  

Ssh 转义字符列表

 ~.      Disconnect.
 ~^Z     Background ssh.
 ~#      List forwarded connections.
 ~&      Background ssh at logout when waiting for forwarded connection / X11 sessions to terminate.
 ~?      Display a list of escape characters.
 ~B      Send a BREAK to the remote system (only useful for SSH protocol version 2 and if the peer supports it).
 ~C      Open command line.  Currently this allows the addition of port forwardings using the -L, -R and -D options (see above).  It also allows the cancellation of existing remote port-forwardings using -KR[bind_address:]port.
         !command allows the user to execute a local command if the PermitLocalCommand option is enabled in ssh_config(5).  Basic help is available, using the -h option.
 ~R      Request rekeying of the connection (only useful for SSH protocol version 2 and if the peer supports it).

相关内容