免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1430 | 回复: 1
打印 上一主题 下一主题

[网络管理] SSH 远程连接服务慢的解决方案 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-05-27 13:46 |只看该作者 |倒序浏览
解决方法:

1、在ssh服务端上更改/etc/ssh/sshd_config文件中的配置为如下内容:
  1. UseDNS no
  2. # GSSAPI options
  3. GSSAPIAuthentication no
复制代码
然后,执行/etc/init.d/sshd restart重启sshd进程使上述配置生效,在连接一般就不慢了。

2、如果还慢的话,检查ssh服务端上/etc/hosts文件中,127.0.0.1对应的主机名是否和 uname -n的结果一样,或者把本机ip和hostname(uname -n结果)加入到/etc/hosts里。
  1. [root@C64 ~]# uname -n
  2. C64
  3. [root@C64 ~]# cat /etc/hosts
  4. #modi by oldboy 11:12 2013/9/24
  5. 127.0.0.1   C64 localhost localhost.localdomain localhost4 localhost4.localdomain4
  6. ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
  7. 10.0.0.18   C64
  8. ################
复制代码
利用ssh -v的调试功能查找慢的原因
其实可以用下面的命令调试为什么慢的细节(学习这个思路很重要)。
  1. [root@C64 ~]# ssh -v root@10.0.0.19
  2. OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
  3. debug1: Reading configuration data /etc/ssh/ssh_config
  4. debug1: Applying options for *
  5. debug1: Connecting to 10.0.0.19 [10.0.0.19] port 22.
  6. debug1: Connection established.
  7. debug1: permanently_set_uid: 0/0
  8. debug1: identity file /root/.ssh/identity type -1
  9. debug1: identity file /root/.ssh/id_rsa type -1
  10. debug1: identity file /root/.ssh/id_dsa type -1
  11. debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
  12. debug1: match: OpenSSH_4.3 pat OpenSSH_4*
  13. debug1: Enabling compatibility mode for protocol 2.0
  14. debug1: Local version string SSH-2.0-OpenSSH_5.3
  15. debug1: SSH2_MSG_KEXINIT sent
  16. debug1: SSH2_MSG_KEXINIT received
  17. debug1: kex: server->client aes128-ctr hmac-md5 none
  18. debug1: kex: client->server aes128-ctr hmac-md5 none
  19. debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
  20. debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
  21. debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
  22. debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
  23. The authenticity of host '10.0.0.19 (10.0.0.19)' can't be established.
  24. RSA key fingerprint is ca:18:42:76:0e:5a:1c:7d:ef:fc:24:75:80:11:ad:f9.
  25. Are you sure you want to continue connecting (yes/no)? yes
  26. =======>老男孩老师评:这里就是提示保存密钥的交互提示。
  27. Warning: Permanently added '10.0.0.19' (RSA) to the list of known hosts.
  28. debug1: ssh_rsa_verify: signature correct
  29. debug1: SSH2_MSG_NEWKEYS sent
  30. debug1: expecting SSH2_MSG_NEWKEYS
  31. debug1: SSH2_MSG_NEWKEYS received
  32. debug1: SSH2_MSG_SERVICE_REQUEST sent
  33. debug1: SSH2_MSG_SERVICE_ACCEPT received
  34. debug1: Authentications that can continue: publickey,password
  35. debug1: Next authentication method: publickey
  36. debug1: Trying private key: /root/.ssh/identity
  37. debug1: Trying private key: /root/.ssh/id_rsa
  38. debug1: Trying private key: /root/.ssh/id_dsa
  39. debug1: Next authentication method: password
  40. root@10.0.0.19's password:
  41. =======>老男孩老师评:这里就是提示输入密码的交互提示。
  42. debug1: Authentication succeeded (password).
  43. debug1: channel 0: new [client-session]
  44. debug1: Entering interactive session.
  45. debug1: Sending environment.
  46. debug1: Sending env LANG = en_US.UTF-8
  47. Last login: Tue Sep 24 10:30:02 2013 from 10.0.0.18
复制代码
在远程连接时如果慢就可以确定卡在哪了。
  1. [root@C64_A ~]# ssh -v oldboy@10.0.0.17
  2. OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
  3. debug1: Reading configuration data /etc/ssh/ssh_config
  4. debug1: Applying options for *
  5. debug1: Connecting to 10.0.0.17 [10.0.0.17] port 22.
  6. debug1: Connection established.
  7. debug1: permanently_set_uid: 0/0
  8. debug1: identity file /root/.ssh/identity type -1
  9. debug1: identity file /root/.ssh/id_rsa type -1
  10. debug1: identity file /root/.ssh/id_dsa type 2
  11. debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
  12. debug1: match: OpenSSH_5.3 pat OpenSSH*
  13. debug1: Enabling compatibility mode for protocol 2.0
  14. debug1: Local version string SSH-2.0-OpenSSH_5.3
  15. debug1: SSH2_MSG_KEXINIT sent
  16. debug1: SSH2_MSG_KEXINIT received
  17. debug1: kex: server->client aes128-ctr hmac-md5 none
  18. debug1: kex: client->server aes128-ctr hmac-md5 none
  19. debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
  20. debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
  21. debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
  22. debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
  23. debug1: Host '10.0.0.17' is known and matches the RSA host key.
  24. debug1: Found key in /root/.ssh/known_hosts:2
  25. debug1: ssh_rsa_verify: signature correct
  26. debug1: SSH2_MSG_NEWKEYS sent
  27. debug1: expecting SSH2_MSG_NEWKEYS
  28. debug1: SSH2_MSG_NEWKEYS received
  29. debug1: SSH2_MSG_SERVICE_REQUEST sent
  30. debug1: SSH2_MSG_SERVICE_ACCEPT received
  31. debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
  32. debug1: Next authentication method: gssapi-keyex
  33. debug1: No valid Key exchange context
  34. debug1: Next authentication method: gssapi-with-mic
复制代码
上述配置没配就发现卡到gssapi这。就大概知道是gssapi的问题。

实际上在linux系统优化部分就应该优化SSH服务的此处。

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
2 [报告]
发表于 2015-05-28 13:38 |只看该作者
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP