SSH连接登录慢的问题和解决方法

发表时间:2018-10-17 13:41 | 分类:Linux | 浏览:1,108 次

用ssh连其他linux机器,会等待10-30秒才有提示输入密码。严重影响工作效率。登录很慢,登录上去后速度正常,这种情况主要有两种可能的原因:
1、dns反向解析
OpenSSH在用户登录的时候会验证IP,它根据用户的IP使用反向DNS找到主机名,再使用DNS找到IP地址,最后匹配一下登录的IP是否合法。如果客户机的IP没有域名,或者DNS服务器很慢或不通,那么登录就会很花时间。
解决办法
在目标服务器上修改sshd服务器端配置,设置UseDNS为no,并重启sshd。

  1. vi /etc/ssh/sshd_config

设置UseDNS为no。

  1. service sshd restart

2、gssapi认证
用ssh -v 可能可以看到类似如下提示:

  1. #下面使用的是GSSAPI-KEYEX来进行验证
  2. debug1: Next authentication method: gssapi-keyex
  3. #但是报错:没有可用的Key来交换信息
  4. debug1: No valid Key exchange context
  5. #系统接着又使用下一个验证方法:GSSAPI-WITH-MIC
  6. debug1: Next authentication method: gssapi-with-mic
  7. #但遗憾的是,GSSAPI-WITH-MIC方法也失败。
  8. #原因:不能确定数字主机地址的域
  9. debug1: Unspecified GSS failure.  Minor code may provide more information
  10. Cannot determine realm for numeric host address
  11. debug1: Unspecified GSS failure.  Minor code may provide more information
  12. Cannot determine realm for numeric host address
  13. debug1: Unspecified GSS failure.  Minor code may provide more information
  14. debug1: Unspecified GSS failure.  Minor code may provide more information
  15. Cannot determine realm for numeric host address
  16. # 在尝试几次后,SSH认证终于放弃了这种验证。进入下一个验证:Publickey
  17. debug1: Next authentication method: publickey

GSSAPI ( Generic Security Services Application Programming Interface) 是一套类似Kerberos 5 的通用网络安全系统接口。该接口是对各种不同的客户端服务器安全机制的封装,以消除安全接口的不同,降低编程难度。但该接口在目标机器无域名解析时会有问题。
解决办法
在目标服务器上修改sshd服务器端配置,设置GSSAPIAuthentication为no,重启sshd服务。

  1. vi /etc/ssh/sshd_config

设置GSSAPIAuthentication为no。

  1. service sshd restart

参考网址:https://linux.cn/article-5851-1.html

本文标签:

本文链接:https://www.sijitao.net/2828.html

欢迎您在本博客中留下评论,如需转载原创文章请注明出处,谢谢!

一键脚本 博客历程 留言联系 文章归档 网站地图 谷歌地图
Copyright © 2010-2024 章郎虫博客 All Rights Reserved.