解決centos的SSH遠端連線服務慢的方法

來源:互聯網
上載者:User

解決centos的SSH遠端連線服務慢的方法

串連慢的主要原因是DNS解析導致

解決方案:

1、在ssh服務端上更改/etc/ssh/sshd_config檔案中的配置為如下內容:
UseDNS no
# GSSAPI options
GSSAPIAuthentication no
然後,執行/etc/init.d/sshd restart重啟sshd進程使上述配置生效,在串連一般就不慢了。

如果還慢的話,檢查ssh服務端上/etc/hosts檔案中,127.0.0.1對應的主機名稱是否和
uname -n的結果一樣,或者把本機ip和hostname(uname -n結果)加入到/etc/hosts裡。

[python]view plaincopy
  1. [root@C64~]#uname-n
  2. C64
  3. [root@C64~]#cat/etc/hosts
  4. #modibyoldboy11:122013/9/24
  5. 127.0.0.1C64localhostlocalhost.localdomainlocalhost4localhost4.localdomain4
  6. ::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain6
  7. 10.0.0.18C64
  8. ################


利用ssh-v的調試功能尋找慢的原因
其實可以用下面的命令調試為什麼慢的細節(學習這個思路很重要)。

[python]view plaincopy
  1. [root@C64~]#ssh-vroot@IP地址
  2. OpenSSH_5.3p1,OpenSSL1.0.0-fips29Mar2010
  3. debug1:Readingconfigurationdata/etc/ssh/ssh_config
  4. debug1:Applyingoptionsfor*
  5. debug1:Connectingto10.0.0.19[10.0.0.19]port22.
  6. debug1:Connectionestablished.
  7. debug1:permanently_set_uid:0/0
  8. debug1:identityfile/root/.ssh/identitytype-1
  9. debug1:identityfile/root/.ssh/id_rsatype-1
  10. debug1:identityfile/root/.ssh/id_dsatype-1
  11. debug1:Remoteprotocolversion2.0,remotesoftwareversionOpenSSH_4.3
  12. debug1:match:OpenSSH_4.3patOpenSSH_4*
  13. debug1:Enablingcompatibilitymodeforprotocol2.0
  14. debug1:LocalversionstringSSH-2.0-OpenSSH_5.3
  15. debug1:SSH2_MSG_KEXINITsent
  16. debug1:SSH2_MSG_KEXINITreceived
  17. debug1:kex:server->clientaes128-ctrhmac-md5none
  18. debug1:kex:client->serveraes128-ctrhmac-md5none
  19. debug1:SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192)sent
  20. debug1:expectingSSH2_MSG_KEX_DH_GEX_GROUP
  21. debug1:SSH2_MSG_KEX_DH_GEX_INITsent
  22. debug1:expectingSSH2_MSG_KEX_DH_GEX_REPLY
  23. Theauthenticityofhost'10.0.0.19(10.0.0.19)'can'tbeestablished.
  24. RSAkeyfingerprintisca:18:42:76:0e:5a:1c:7d:ef:fc:24:75:80:11:ad:f9.
  25. Areyousureyouwanttocontinueconnecting(yes/no)?yes
  26. =======>這裡就是提示儲存密鑰的互動提示。
  27. Warning:Permanentlyadded'10.0.0.19'(RSA)tothelistofknownhosts.
  28. debug1:ssh_rsa_verify:signaturecorrect
  29. debug1:SSH2_MSG_NEWKEYSsent
  30. debug1:expectingSSH2_MSG_NEWKEYS
  31. debug1:SSH2_MSG_NEWKEYSreceived
  32. debug1:SSH2_MSG_SERVICE_REQUESTsent
  33. debug1:SSH2_MSG_SERVICE_ACCEPTreceived
  34. debug1:Authenticationsthatcancontinue:publickey,password
  35. debug1:Nextauthenticationmethod:publickey
  36. debug1:Tryingprivatekey:/root/.ssh/identity
  37. debug1:Tryingprivatekey:/root/.ssh/id_rsa
  38. debug1:Tryingprivatekey:/root/.ssh/id_dsa
  39. debug1:Nextauthenticationmethod:password
  40. root@10.0.0.19'spassword:
  41. <strong>=======>這裡就是提示輸入密碼的互動提示。</strong>
  42. debug1:Authenticationsucceeded(password).
  43. debug1:channel0:new[client-session]
  44. debug1:Enteringinteractivesession.
  45. debug1:Sendingenvironment.
  46. debug1:SendingenvLANG=en_US.UTF-8
  47. Lastlogin:TueSep2410:30:022013from10.0.0.18
  48. <strong>在遠端連線時如果慢就可以確定卡在哪了。</strong>
  49. [root@C64_A~]#ssh-voldboy@IP地址
  50. OpenSSH_5.3p1,OpenSSL1.0.0-fips29Mar2010
  51. debug1:Readingconfigurationdata/etc/ssh/ssh_config
  52. debug1:Applyingoptionsfor*
  53. debug1:Connectingto10.0.0.17[10.0.0.17]port22.
  54. debug1:Connectionestablished.
  55. debug1:permanently_set_uid:0/0
  56. debug1:identityfile/root/.ssh/identitytype-1
  57. debug1:identityfile/root/.ssh/id_rsatype-1
  58. debug1:identityfile/root/.ssh/id_dsatype2
  59. debug1:Remoteprotocolversion2.0,remotesoftwareversionOpenSSH_5.3
  60. debug1:match:OpenSSH_5.3patOpenSSH*
  61. debug1:Enablingcompatibilitymodeforprotocol2.0
  62. debug1:LocalversionstringSSH-2.0-OpenSSH_5.3
  63. debug1:SSH2_MSG_KEXINITsent
  64. debug1:SSH2_MSG_KEXINITreceived
  65. debug1:kex:server->clientaes128-ctrhmac-md5none
  66. debug1:kex:client->serveraes128-ctrhmac-md5none
  67. debug1:SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192)sent
  68. debug1:expectingSSH2_MSG_KEX_DH_GEX_GROUP
  69. debug1:SSH2_MSG_KEX_DH_GEX_INITsent
  70. debug1:expectingSSH2_MSG_KEX_DH_GEX_REPLY
  71. debug1:Host'10.0.0.17'isknownandmatchestheRSAhostkey.
  72. debug1:Foundkeyin/root/.ssh/known_hosts:2
  73. debug1:ssh_rsa_verify:signaturecorrect
  74. debug1:SSH2_MSG_NEWKEYSsent
  75. debug1:expectingSSH2_MSG_NEWKEYS
  76. debug1:SSH2_MSG_NEWKEYSreceived
  77. debug1:SSH2_MSG_SERVICE_REQUESTsent
  78. debug1:SSH2_MSG_SERVICE_ACCEPTreceived
  79. debug1:Authenticationsthatcancontinue:publickey,gssapi-keyex,gssapi-with-mic,password
  80. debug1:Nextauthenticationmethod:gssapi-keyex
  81. debug1:NovalidKeyexchangecontext
  82. debug1:Nextauthenticationmethod:gssapi-with-mic
上述配置沒配就發現卡到gssapi這。就大概知道是gssapi的問題。

實際上在linux系統最佳化部分就應該最佳化SSH服務的此處。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.