OpenSSH:在伪终端中打字速度慢

elm*_*mis 6 ssh openssh

更新

  • 我已将其范围缩小到仅发生在工作中的无线网络上。从家里,我没有遇到任何滞后/延迟
  • 似乎在“大量”使用 SSH 并通过一两台机器建立隧道后,网络完全掉线,我被迫手动重新连接
  • 看看 WireShark 从 OpenSSH 与 JSch 捕获的 SSH 会话,OpenSSH 似乎有一些TCP Dup AckTCP RetransmissionTCP Spurious Retransmission数据包。但这些应该自行解决,因为 TCP ..

问题

最近,当使用 SSH 连接到远程计算机时,我注意到在我输入内容和实际出现的字符之间存在大约 1 秒的明显延迟。如果我按住按键,它们将以大约 20 个字符的“批次”形式出现,间隔约为 1 秒。

系统详情

$ ssh -V
    OpenSSH_7.2p2 Ubuntu-4ubuntu1, OpenSSL 1.0.2g-fips  1 Mar 2016        
Run Code Online (Sandbox Code Playgroud)
$回显$SHELL $TERM $DISPLAY
    /bin/zsh xterm-256color :0
$ uname -r; 猫/过程/版本
    4.4.0-22-通用
    Linux 版本 4.4.0-22-generic (buildd@lgw01-41) (gcc 版本 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2) ) #40-Ubuntu SMP 5 月 12 日星期四 22:03:46 UTC 2016

观察结果

一个奇怪的观察结果是,仅当分配伪终端时(即默认情况或 -t 选项),才会出现延迟。当伪终端被强制禁用时,我可以立即键入命令并获取其输出。

  • 我的 ~/.ssh/config 文件仅包含“以下格式的纯条目:
主持某人
    主机名 192.168.1.0
    用户 someuser
    身份文件 ~/.ssh/id_rsa
  • 当我显式禁用伪终端(即使用 -T 选项)时没有延迟
  • 更改类似问题中提到的设置无法解决问题
  • IntelliJ Idea Ultimate Edition 可以创建存在此问题的 SSH 连接。IDE 正在运行 Java SSH 客户端JSch
    • 这让我确信这是一个本地问题,可能与我的网络接口无关
  • 我在同一网络上的同事没有这个问题,尽管他们使用的是 Macbook

我尝试过的

  • 启用压缩、禁用X11转发、加速登录过程的各种方法
  • 通过 SSH 连接到本地主机(这里没有滞后/延迟
  • 通过 SSH 连接到多种机器(即不仅仅是一台机器)——存在延迟
  • 下载 OpenSSH 的最新稳定版本并为我的系统构建它
    • 新编译的二进制文件也有同样的问题,让我认为这是由一些不稳定的配置引起的
  • 确保我的 /etc/ssh/ssh_config 看起来“正常”
    • 我已将其包含在帖子末尾以防万一
  • 清除 SSH 并使用 apt-get 重新安装
  • 使用 Ctrl + Alt + F{1-6} 进入虚拟 TTY(我想这就是他们的名字……)并从那里进行 SSH
  • 重新启动
  • 切换到不同的网络
    • 滞后/延迟似乎只是工作中网络上的一个问题。在家里,没有明显的延迟/滞后
  • 其他一些我忘记的事情

太长了;博士

我的 SSH 二进制文件/配置/某些内容在输入时似乎有延迟,并且我尝试了很多方法但没有成功。也许这是一些字符缓冲区的事情?谁知道!希望你能做到。

ssh-vvv

OpenSSH_7.2p2 Ubuntu-4ubuntu1、OpenSSL 1.0.2g-fips 2016 年 3 月 1 日
debug1:读取配置数据/home/redacted/.ssh/config
debug1: /home/redacted/.ssh/config 第 6 行:为 ops1 应用选项
debug1:读取配置数据/etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config 第 19 行:应用 * 的选项
debug2:解析“xx.xx.xx.xx”端口 22
debug2:ssh_connect_direct:needpriv 0
debug1:连接到 xx.xx.xx.xx [xx.xx.xx.xx] 端口 22。
debug1:连接已建立。
debug1:身份文件 /home/redacted/.ssh/id_rsa 类型 1
debug1: key_load_public: 没有这样的文件或目录
debug1:身份文件 /home/redacted/.ssh/id_rsa-cert 类型 -1
debug1:启用协议2.0的兼容模式
debug1:本地版本字符串 SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu1
debug1:远程协议版本2.0,远程软件版本OpenSSH_5.3
debug1:匹配:OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000000
debug2: fd 3 设置 O_NONBLOCK
debug1:将 xx.xx.xx.xx:22 验证为“redacted2”
debug3:hostkeys_foreach:读取文件“/home/redacted/.ssh/known_hosts”
debug3: record_hostkey: 在文件 /home/redacted/.ssh/known_hosts:2 中找到密钥类型 RSA
debug3: load_hostkeys: 从 xx.xx.xx.xx 加载 1 个密钥
debug3:order_hostkeyalgs:更喜欢hostkeyalgs:ssh-rsa-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug3:发送数据包:类型20
debug1:SSH2_MSG_KEXINIT 已发送
debug3:接收数据包:类型20
debug1:收到 SSH2_MSG_KEXINIT
debug2:本地客户端 KEXINIT 提案
debug2:KEX算法:curve25519-sha256@libssh.org、ecdh-sha2-nistp256、ecdh-sha2-nistp384、ecdh-sha2-nistp521、diffie-hellman-group-exchange-sha256、diffie-hellman-group-exchange-sha1 ,diffie-hellman-group14-sha1,ext-info-c
debug2:主机密钥算法:ssh-rsa-cert-v01@openssh.com、rsa-sha2-512、rsa-sha2-256、ssh-rsa、ecdsa-sha2-nistp256-cert-v01@openssh.com、ecdsa- sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384, ECDSA-SHA2-nistp521,ssh-ed25519
debug2:密码ctos:chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256 -cbc,3des-cbc
debug2:密码stoc:chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256 -cbc,3des-cbc
debug2:MAC ctos:umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac -sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2:MAC stoc:umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac -sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2:压缩ctos:无,zlib@openssh.com,zlib
debug2:压缩 stoc:无,zlib@openssh.com,zlib
debug2: 语言 ctos:
debug2:语言库存:
调试2:first_kex_follows 0
调试2:保留0
debug2:对等服务器 KEXINIT 提案
debug2:KEX算法:diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2:主机密钥算法:ssh-rsa、ssh-dss
debug2:密码ctos:aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc @lysator.liu.se
debug2:密码stoc:aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc @lysator.liu.se
debug2:MAC ctos:hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96 ,hmac-md5-96
debug2:MAC stoc:hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96 ,hmac-md5-96
debug2:压缩ctos:无,zlib@openssh.com
debug2:压缩 stoc:无,zlib@openssh.com
debug2: 语言 ctos:
debug2:语言库存:
调试2:first_kex_follows 0
调试2:保留0
debug1: kex: 算法: diffie-hellman-group-exchange-sha256
debug1:kex:主机密钥算法:ssh-rsa
debug1: kex: 服务器->客户端 密码: aes128-ctr MAC: umac-64@openssh.com 压缩: 无
debug1: kex: 客户端->服务器 密码: aes128-ctr MAC: umac-64@openssh.com 压缩: 无
debug3:发送数据包:类型 34
debug1:SSH2_MSG_KEX_DH_GEX_REQUEST(2048已关闭
debug3:接收数据包:类型96
debug2: 通道 0: rcvd eof
debug2:通道 0:输出打开 -> 漏极
debug3:接收数据包:类型97
debug2: 通道 0: rcvd 关闭
debug3:通道0:关闭后不会发送数据
登出
debug3:通道0:关闭后不会发送数据
debug2: 通道 0: obuf 空
debug2: 通道 0: close_write
debug2:通道 0:输出漏极 -> 关闭
debug2:通道 0:几乎死了
debug2: 通道 0: gc: 通知用户
debug2: 通道 0: gc: 用户分离
debug2: 通道 0: 发送关闭
debug3:发送数据包:类型97
debug2: 通道 0: 已死
debug2:通道 0:垃圾收集
debug1:通道 0:空闲:客户端会话,nchannels 1
debug3:通道 0:状态:以下连接已打开:
  #0 客户端会话 (t4 r0 i3/0 o3/0 fd -1/-1 cc -1)

debug3:发送数据包:类型1
debug1: fd 1 清除 O_NONBLOCK
debug3:fd 2 不是 O_NONBLOCK
与 xx.xx.xx.xx 的连接已关闭。
已传输:发送 3376 个字节,接收 3072 个字节,0.8 秒
每秒字节数:发送 3981.4,接收 3622.9
debug1:退出状态0

ssh-vvvT

OpenSSH_7.2p2 Ubuntu-4ubuntu1、OpenSSL 1.0.2g-fips 2016 年 3 月 1 日
debug1:读取配置数据/home/redacted/.ssh/config
debug1: /home/redacted/.ssh/config 第 6 行:为 ops1 应用选项
debug1:读取配置数据/etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config 第 19 行:应用 * 的选项
debug2:解析“xx.xx.x.xx”端口 22
debug2:ssh_connect_direct:needpriv 0
debug1:连接到 xx.xx.x.xx [xx.xx.x.xx] 端口 22。
debug1:连接已建立。
debug1:身份文件 /home/redacted/.ssh/id_rsa 类型 1
debug1: key_load_public: 没有这样的文件或目录
debug1:身份文件 /home/redacted/.ssh/id_rsa-cert 类型 -1
debug1:启用协议2.0的兼容模式
debug1:本地版本字符串 SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu1
debug1:远程协议版本2.0,远程软件版本OpenSSH_5.3
debug1:匹配:OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000000
debug2: fd 3 设置 O_NONBLOCK
debug1:将 xx.xx.x.xx:22 验证为“已编辑”
debug3:hostkeys_foreach:读取文件“/home/redacted/.ssh/known_hosts”
debug3: record_hostkey: 在文件 /home/redacted/.ssh/known_hosts:2 中找到密钥类型 RSA
debug3: load_hostkeys: 从 xx.xx.x.xx 加载 1 个密钥
debug3:order_hostkeyalgs:更喜欢hostkeyalgs:ssh-rsa-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug3:发送数据包:类型20
debug1:SSH2_MSG_KEXINIT 已发送
debug3:接收数据包:类型20
debug1:收到 SSH2_MSG_KEXINIT
debug2:本地客户端 KEXINIT 提案
debug2:KEX算法:curve25519-sha256@libssh.org、ecdh-sha2-nistp256、ecdh-sha2-nistp384、ecdh-sha2-nistp521、diffie-hellman-group-exchange-sha256、diffie-hellman-group-exchange-sha1 ,diffie-hellman-group14-sha1,ext-info-c
debug2:主机密钥算法:ssh-rsa-cert-v01@openssh.com、rsa-sha2-512、rsa-sha2-256、ssh-rsa、ecdsa-sha2-nistp256-cert-v01@openssh.com、ecdsa- sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384, ECDSA-SHA2-nistp521,ssh-ed25519
debug2:密码ctos:chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256 -cbc,3des-cbc
debug2:密码stoc:chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256 -cbc,3des-cbc
debug2:MAC ctos:umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac -sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2:MAC stoc:umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac -sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2:压缩ctos:无,zlib@openssh.com,zlib
debug2:压缩 stoc:无,zlib@openssh.com,zlib
debug2: 语言 ctos:
debug2:语言库存:
调试2:first_kex_follows 0
调试2:保留0
debug2:对等服务器 KEXINIT 提案
debug2:KEX算法:diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2:主机密钥算法:ssh-rsa、ssh-dss
debug2:密码ctos:aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc @lysator.liu.se
debug2:密码stoc:aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc @lysator.liu.se
debug2:MAC ctos:hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96 ,hmac-md5-96
debug2:MAC stoc:hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96 ,hmac-md5-96
debug2:压缩ctos:无,zlib@openssh.com
debug2:压缩 stoc:无,zlib@openssh.com
debug2: 语言 ctos:
debug2:语言库存:
调试2:first_kex_follows 0
调试2:保留0
debug1: kex: 算法: diffie-hellman-group-exchange-sha256
debug1:kex:主机密钥算法:ssh-rsa
debug1: kex: 服务器->客户端 密码: aes128-ctr MAC: umac-64@openssh.com 压缩: 无
debug1: kex: 客户端->服务器 密码: aes128-ctr MAC: umac-64@openssh.com 压缩: 无
debug3:发送数据包:类型 34
debug1:SSH2_MSG_KEX_DH_GEX_REQUEST(2048漏
debug2:通道 0:ibuf 空
debug2: 通道 0: 发送 eof
debug3:发送数据包:类型96
debug2:通道 0:输入漏极 -> 关闭
debug3:接收数据包:类型98
debug1:client_input_channel_req:通道0 rtype退出状态回复0
debug3:接收数据包:类型96
debug2: 通道 0: rcvd eof
debug2:通道 0:输出打开 -> 漏极
debug2: 通道 0: obuf 空
debug2: 通道 0: close_write
debug2:通道 0:输出漏极 -> 关闭
debug3:接收数据包:类型97
debug2: 通道 0: rcvd 关闭
debug3:通道0:关闭后不会发送数据
debug2:通道 0:几乎死了
debug2: 通道 0: gc: 通知用户
debug2: 通道 0: gc: 用户分离
debug2: 通道 0: 发送关闭
debug3:发送数据包:类型97
debug2: 通道 0: 已死
debug2:通道 0:垃圾收集
debug1:通道 0:空闲:客户端会话,nchannels 1
debug3:通道 0:状态:以下连接已打开:
  #0 客户端会话 (t4 r0 i3/0 o3/0 fd -1/-1 cc -1)

debug3:发送数据包:类型1
debug1: fd 1 清除 O_NONBLOCK
debug3:fd 2 不是 O_NONBLOCK
已传输:发送 3040 个字节,接收 2800 个字节,用时 1.9 秒
每秒字节数:发送 1598.6,接收 1472.4
debug1:退出状态0

/etc/ssh/ssh_config

# 这是 ssh 客户端系统范围的配置文件。看
# ssh_config(5) 了解更多信息。该文件提供了默认值
# 个用户,这些值可以在每个用户的配置文件中更改
# 或在命令行上。

# 配置数据解析如下:
# 1. 命令行选项
# 2.用户特定文件
# 3.系统范围的文件
# 任何配置值仅在第一次设置时才会更改。
# 因此,特定于主机的定义应该位于
# 配置文件,默认在最后。

# 一些常用选项的站点范围默认值。为了全面
# 可用选项列表、它们的含义和默认值,请参阅
# ssh_config(5) 手册页。

主持人 *
# 转发代理没有
#ForwardX11 否
# ForwardX11Trusted 是
# RhostsRSAAuthentication 否
# RSA身份验证 是
# 密码验证是
# 基于主机的身份验证 否
# GSSAPI 身份验证 否
# GSSAPIDelegateCredentials 否
# GSSAPIKeyExchange 是
#GSSAPITrustDNS 否
# 批处理模式 否
# 检查主机IP 是
# 地址家族任意
# 连接超时 0
# StrictHostKeyChecking 询问
# 身份文件 ~/.ssh/identity
# 身份文件 ~/.ssh/id_rsa
# 身份文件 ~/.ssh/id_dsa
# 身份文件 ~/.ssh/id_ecdsa
# 身份文件~/.ssh/id_ed25519
# 端口 22
# 协议2
# 密码 3des
# 密码 aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
# MAC hmac-md5、hmac-sha1、umac-64@openssh.com、hmac-ripemd160
# 逃脱角色 ~
# 隧道号
# TunnelDevice 任意:任意
# 允许本地命令否
# VisualHostKey 没有
# ProxyCommand ssh -q -W %h:%p gateway.example.com
# RekeyLimit 1G 1h
# SendEnv LANG LC_*
    HashKnownHosts 是
   # GSSAPI身份验证 是
   # GSSAPIDelegateCredentials 否

stu*_*eja 1

不幸的是我还不能发表评论。

我对客户的看法是:

你有没有看过topCPU负载?也许 SSH 进程会占用 CPU 进行加密。

你有没有看过ssh -v[vv]并检查过一些奇怪的地方?也许服务器和客户端就非常安全的密码或 MAC 达成一致。看看

debug2: ciphers ctos: arcfour
debug2: ciphers stoc: arcfour
[...]
debug1: kex: server->client cipher: arcfour MAC: hmac-sha2-256-etm@openssh.com compression: zlib@openssh.com
debug1: kex: client->server cipher: arcfour MAC: hmac-sha2-256-etm@openssh.com compression: zlib@openssh.com
Run Code Online (Sandbox Code Playgroud)

(其中 arcfour 实际上是最弱、CPU 占用率最低的算法之一。我通过 SSH 代理进行连接)。另外,查找重新加密消息。

此外,压缩可能是一个问题。然而,ssh在这里似乎对压缩级别并没有太明确。

debug2: compression ctos: zlib@openssh.com,zlib,none
debug2: compression stoc: zlib@openssh.com,zlib,none
Run Code Online (Sandbox Code Playgroud)

您没有明确说明您的远程服务器有多“远程”。在同一个网络中,在同一个校园的不同网络中,通过互联网?

如果通过互联网,也许您的公司防火墙正在深入检查端口 22 上的 SSH 流量。如果您可以控制 SSH 服务器文件,也许更改端口会有所帮助/etc/ssh/sshd_config

如果通过互联网,SSH 是您使用的“唯一”隧道,还是您通过其他 VPN 使用 SSH?

如果在同一个园区,我还会想到防火墙、路由、检查问题。我曾经因为我的互联网问题而指责我的互联网提供商;太慢了。持续了好几天。直到我发现我在我的思科路由器上启用了调试,这消耗了那里的资源。

如果是本地或远程,您是直接连接还是通过 SSH 代理、网关或跳转主机连接?在这种情况下,就像使用 VPN 一样,您拥有双重加密。