2012-08-28 14:29:59 +0000 2012-08-28 14:29:59 +0000
273
273

我如何退出SSH连接?

我通过SSH连接到服务器上,通过SSH向套接字服务器发送消息,使用的命令是:

ssh 181.169.1.2 -p 5566

连接建立后,我写了消息并发送后,我无法退出文本模式,只能输入更多的文本。

有没有一个命令或组合键可以让我返回到命令模式?

答案 (7)

294
294
294
2013-07-17 09:26:09 +0000

简单的答案是: 输入exit

如果不行的话…..

SSH转义字符和断开连接序列

大多数SSH实现了交互式会话的转义字符,类似于telnet的Ctrl-]组合。默认的SSH转义字符是~,在行的开头输入。

如果你想终止一个交互式的OpenSSH会话 **被卡住了,无法通过在远程侧的shell中输入exit或CtrlD来退出*,你可以在~后面输入一个点.。为了确保在输入行的开头输入转义字符,应该先按回车键。所以在大多数情况下,下面的序列将终止一个SSH会话:

Enter~.*

其他转义序列

例如,除了~.之外,OpenSSH还提供了其他转义序列。在一个会话中输入~?,应该会给你一个列表。一些例子:

  • ~后面的Ctrl-Z会暂停会话,
  • ~&会直接将其转入后台,
  • ~#会给出一个转发连接的列表。如果你设置了特殊值 ~~,转义字符将被禁用,并且会话是完全透明的。
195
195
195
2017-09-16 21:57:26 +0000

如何退出SSH连接?

两种方法:

—关闭shell会话,比如用exit跟着Enter键,或者Ctrl-d通常可以正常退出ssh会话, —在连接不好,shell没有反应的情况下,按回车键,然后键入~.,ssh应该会立即关闭,并返回到命令提示符。

第一个选项应该很直观,但是我们怎么知道后一个选项呢?

我们可以通过仔细阅读man page来了解这些信息,

$ 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.
32
32
32
2012-08-28 18:37:35 +0000

你想退出SSH shell吗?

你可以输入exit,然后按回车键,或者使用Ctrl+D

11
11
11
2014-04-14 15:00:24 +0000

只需输入exitlogout(当然,然后按回车键)就可以了。

8
8
8
2016-06-14 22:26:47 +0000

这些是支持的字符,它提供了各种选项,你可以玩转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

(注意,转义符只有在换行后才会被识别。)你可以通过点击回车键关闭转义序列列表。

3
3
3
2013-07-17 07:12:49 +0000

你可以在控制台行中写上logout(当然是按回车键)。

1
1
1
2018-03-29 17:25:28 +0000

MacOS:当ssh挂起时,使用以下顺序:

ENTER 
SHIFT+`
.

,其中: shift+`会产生~*** (tilde字符)