从shell SSH登录华为 S5720s 慢,输入用户名后15秒才登录上

文章讲述了在Linux/FreeBSD系统下通过SSH登录华为S5720s交换机时出现登录延迟的问题,原因是密钥交换算法的选择。实验发现dh_group14_sha256算法耗时最短。解决方案包括手动指定该算法作为SSH登录参数或修改ssh_config配置文件以优化登录速度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述:

从Linux/FreeBSD shell SSH登录华为 S5720s 慢,输入用户名后15秒才登录上。同一台交换机用Secure-CRT直接登录只需等5秒。

相关配置:

Linux/FreeBSD:
#
 /etc/ssh/ssh_config :默认

登录用命令行:

#ssh -i /root/.ssh/s5720s -l admin 192.168.1.1

S5720s:
 

S5720S#
rsa peer-public-key s5720s
 public-key-code begin
…………
public-key-code end                      
peer-public-key end
#
 local-user admin service-type ssh
#
stelnet server enable
ssh user admin
ssh user admin authentication-type all
ssh user admin assign rsa-key s5720s
ssh user admin service-type all
#

处理过程:

根据经验,ssh登陆时间长一般是发生在计算密钥阶段。

1. 在S5720s上提问它提供了哪些密钥交换算法:

S5720s#ssh server key-exchange ?
  dh_group14_sha256         Diffie-hellman-group14-sha256 key exchange
                            algorithm
  dh_group15_sha512         Diffie-hellman-group15-sha512 key exchange
                            algorithm
  dh_group16_sha512         Diffie-hellman-group16-sha512 key exchange
                            algorithm
  dh_group_exchange_sha256  Diffie-hellman-group-exchange-sha256 key exchange
                            algorithm, and this algorithm is recommended

S5720s内置默认提供了四种密钥交换的算法,分别为  dh_group14_sha256、 dh_group15_sha512、dh_group16_sha512、dh_group_exchange_sha256,这个顺序也是密钥交换算法的安全级别由低到高的顺序。密钥交换算法越高越安全,但需要计算密钥的时间也会越长,而不同的交换机其核心运算芯片处理能力不同,性能越弱的设备计算时间越长。从安全角度,当然推荐使用最高的密钥交换算法,但这个算法会比较耗时。

Secure-CRT里面的密钥交换顺序是由低到高,而Linux/FreeBSD的shell 中的ssh 默认的密钥交换模式是比较高的,从而导致登录时间的差异。

2. 分别使用四种不同的密钥交换算法,用以下命令进行实验,测试登录时间的差异:

Linux#ssh -oKexAlgorithms=diffie-hellman-group14-sha256 -i /root/.ssh/s5720s -l admin 192.168.1.1 

Linux# time ssh -oKexAlgorithms=diffie-hellman-group14-sha256 -i /root/.ssh/s5720s -l admin 192.168.1.1

Info: The max number of VTY users is 10, and the number
      of current VTY users on line is 1.
      The current login time is 2023-03-05 22:41:03+08:00.
<S5720S>quit
Info: The max number of VTY users is 10, and the number
      of current VTY users on line is 0.Connection to 192.168.1.1 closed.
0.022u 0.000s 0:05.38 0.3%      168+144k 0+0io 0pf+0w

Linux#ssh -oKexAlgorithms=diffie-hellman-group15-sha512 -i /root/.ssh/s5720s -l admin 192.168.1.1 

Linux# time ssh -oKexAlgorithms=diffie-hellman-group15-sha512 -i /root/.ssh/s5720s -l admin 192.168.1.1
Unsupported KEX algorithm "diffie-hellman-group15-sha512"
command-line line 0: Bad SSH2 KexAlgorithms 'diffie-hellman-group15-sha512'.
0.004u 0.000s 0:00.00 0.0%      0+0k 0+0io 0pf+0w

Linux#ssh -oKexAlgorithms=diffie-hellman-group16-sha512 -i /root/.ssh/s5720s -l admin 192.168.1.1 

Linux# time ssh -oKexAlgorithms=diffie-hellman-group16-sha512 -i /root/.ssh/s5720s -l admin 192.168.1.1

Info: The max number of VTY users is 10, and the number
      of current VTY users on line is 1.
      The current login time is 2023-03-05 22:47:57+08:00.
<S5720S>quit
Info: The max number of VTY users is 10, and the number
      of current VTY users on line is 0.Connection to 192.168.1.1 closed.
0.030u 0.000s 0:14.95 0.2%      112+96k 0+0io 0pf+0w

Linux#ssh -oKexAlgorithms=diffie-hellman-group-exchange-sha256 -i /root/.ssh/s5720s -l admin 192.168.1.1 

Linux# time ssh -oKexAlgorithms=diffie-hellman-group-exchange-sha256 -i /root/.ssh/s5720s -l admin 192.168.1.1

Info: The max number of VTY users is 10, and the number
      of current VTY users on line is 1.
      The current login time is 2023-03-05 22:49:33+08:00.
<S5720S>quit
Info: The max number of VTY users is 10, and the number
      of current VTY users on line is 0.Connection to 192.168.1.1 closed.
0.021u 0.014s 0:14.97 0.2%      280+240k 0+0io 0pf+0w

从实验测得:

使用 dh_group14_sha256、 dh_group15_sha512、dh_group16_sha512、dh_group_exchange_sha256四种密钥交换算法登录S5720S 耗时分别为 0:05.38、Unsupported 、0:14.95、0:14.97秒,其中dh_group14_sha256密钥交换算法 耗时最短大概5秒左右,dh_group16_sha512、dh_group_exchange_sha256 两种密钥交换算法耗时在15秒左右,Linux 不支持 dh_group15_sha512密钥交换算法。

解决方案:

1. 以后使用ssh 命令行参数ssh -oKexAlgorithms=diffie-hellman-group14-sha256 指定 dh_group14_sha256 密钥交换算法 登录S5720S ,即可解决问题。

2. 如果是expect脚本使用,则使用ssh 命令行参数ssh -oKexAlgorithms=diffie-hellman-group14-sha256解决问题。

3. 如果是偶尔使用ssh 命令行,命令行参数实在拗口难记,不加也无所谓啦,多忍10秒而已,等这堆参数背出来输完10秒也过去了。

4. 经常使用ssh 命令行登录S5720s 交换机,则需配置 ssh_config ,优先使用diffie-hellman-group14-sha256 密钥交换算法:

Linux:

编辑 /etc/ssh/ssh_config 文件:

Linux#vi /etc/ssh/ssh_config

在文件中找到Host * 配置块,在最后一行换行,添加以下行:

KexAlgorithms diffie-hellman-group14-sha256

测试: 

# time ssh -i /root/.ssh/s5720s -l admin 192.168.1.1 

Info: The max number of VTY users is 10, and the number
      of current VTY users on line is 1.
      The current login time is 2023-03-05 23:05:57+08:00.
<S5720S-28P>quit
Info: The max number of VTY users is 10, and the number
      of current VTY users on line is 0.Connection to 192.168.1.1 closed.
0.024u 0.000s 0:05.23 0.3%      420+360k 0+0io 0pf+0w

完工。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值