歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 內網用SSH連接Linux很慢

內網用SSH連接Linux很慢

日期:2017/2/28 15:59:39   编辑:Linux教程

網上關於該問題的常用解決方法是(主要就是修改配置文件/etc/ssh/sshd_config):

(1)修改"UseDNS"的值為“no”(沒有的添加該配置選項,注釋掉的放開即可);這種修改在我的系統裡面好像沒起作用!

(2)修改“GSSAPIAuthentication”的值為“no”(沒有的添加該配置選項,注釋掉的放開即可);

其實用戶可以自己運行“ssh -v host”進行debug的,通過debug信息就可以看到連接到什麼地方被耽擱了;我的測試就是在"debug1: Unspecified GSS failure. Minor code may provide more information" 這裡停頓了一會兒,所以感覺修改“GSSAPIAuthentication”的值應該會有效果,但實踐證明,如果不改上面幾項,該處更改在我的系統依然不起作用!

解決ssh連接慢(有時候等半分鐘才出現密碼輸入提示)的方法

經常通過ssh 或者 scp 連接一堆遠程主機,同樣是 Linux 主機,其中一些創建 ssh 連接速度特別慢,連接建立之後執行操作速度卻很正常,看來應該不是網絡原因。解決的方法是通過ssh 的-v參數來查看調試信息的:

用 ssh -v 來查看詳細的連接建立過程,馬上用一台建立連接很慢的主機試了一下,在一大堆輸出信息中發現在這裡停留最久:

debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure. Minor code may provide more information
No credentials cache found

debug1: Unspecified GSS failure. Minor code may provide more information

debug1: Next authentication method: publickey

原來是因為嘗試了個沒有意義而且會失敗的 gssapi-with-mic 認證方式浪費了時間,打開(遠程服務器) /etc/ssh/ssh_config 把裡面的 GSSAPIAuthentication yes 改成 no 關掉它,即可讓 ssh 直接嘗試美妙的 publickey 認證方式。

禁用 GSSAPIAuthentication 前後建立 ssh 連接時間的對比:

view plaincopy to clipboardprint?
root@server:~$ time ssh [email protected] exit

real 0m18.488s
user 0m0.004s
sys 0m0.008s
root@server:~$ time ssh [email protected] exit

real 0m3.531s
user 0m0.016s
sys 0m0.000s

Copyright © Linux教程網 All Rights Reserved