Answers:
如何退出SSH连接?
两种方式:
exit
后跟Enter或Ctrl- d通常可以让您ssh
正常退出会话,~.
and ssh应该立即关闭并使您返回命令提示符。第一个选项应该直观,但是我们如何知道后一个选项?
我们可以通过仔细阅读手册页来学习此信息。
$ man ssh
向我们提供了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.
~# 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 if the peer sup‐
ports 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 port-forwardings with
-KL[bind_address:]port for local, -KR[bind_address:]port for
remote and -KD[bind_address:]port for dynamic port-forwardings.
!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 if the peer
supports it).
~V Decrease the verbosity (LogLevel) when errors are being written
to stderr.
~v Increase the verbosity (LogLevel) when errors are being written
to stderr.
简短答案:类型 exit
如果那不起作用,但是...
大多数SSH实现都为交互式会话实现转义字符,类似于telnet的Ctrl-]
组合。SSH的默认转义字符是~
,在行的开头输入。
如果您想终止交互式OpenSSH会话,该exit
CtrlD会话被卡住了,无法通过进入或进入远程端的Shell 来退出,则可以输入~
一个加点号.
。为确保在输入行的开头输入转义字符,应首先按Enter。因此,在大多数情况下,以下顺序将终止SSH会话:
Enter~.
例如,OpenSSH除了提供其他转义序列~.
。~?
在会话期间输入应该会给您一个列表。一些例子:
~
然后Ctrl-Z
暂停会话,~&
将其直接放入背景~#
提供此会话中转发连接的列表。 ~~
。可以使用命令行选项更改转义符-e
。如果设置特殊值-e none
,将禁用转义并且会话是完全透明的。
另请参见命令行选项下ssh上的OpenBSD手册页(从www.openssh.org进行引用)。-e
exit
或Ctrl-D
只有一个侦听过程的情况。我明确指出,我的解决方案适用于卡住且无法退出的会话。我试图进一步澄清这一点,希望现在可以更容易地看到。
~.
没有空格正是我所需要的,谢谢!:)
您要退出SSH Shell吗?
您可以输入exit
并点击Enter,也可以使用Ctrl+D
这些是受支持的字符,这些字符提供了各种选项,您可以在这些选项中使用ssh。
支持的转义序列:
~. - terminate session
~B - send a BREAK to the remote system
~R - Request rekey (SSH protocol 2 only)
~# - list forwarded connections
~? - this message
~~ - send the escape character by typing it twice
(请注意,转义只能在换行符后立即识别。)您可以通过点击来关闭转义序列列表Enter。
MacOS:ssh挂起时,请使用以下顺序:
ENTER
SHIFT+`
.
其中: shift +` 产生〜(波浪号)