解決方案: scp/ssh 的登陸提示很慢 (Linux)

meetrice發表於2016-03-23
看著用 windows 的 scp 命令很快很是羨慕. 這個問題讓我實實鬱悶了好幾天. 在 Linux 下不管是用 ssh 還是用 scp, 連線速度都很慢 (登陸提示框的彈出時間).
確切地講, 每次的登陸連線平均消耗了 30 秒! 
言歸正傳. 如何找出究竟是什麼導致了 ssh 或是 scp 的登陸很慢? 如何修復該所謂的登陸 "慢" 或 "延遲"?
今天 Google 了一下, 很快就有了解決方案. :-) 
你也 google 了吧? :-)

什麼導致了 scp 和 ssh 的登陸提示速度下降

就我自身所遇到的情況來看, 這些延遲絕大部分是 GSSAPI 的認證功能導致的!
你可以用 -v  選項確認你的情況. 例如, 下面是 ssh 的詳細登陸過程:
cherry@cherry:~$ ssh -v cherry@59.151.47.49
...
...
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
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
debug1: Trying private key: /home/cherry/.ssh/identity
debug1: Trying private key: /home/cherry/.ssh/id_rsa
debug1: Trying private key: /home/cherry/.ssh/id_dsa
debug1: Next authentication method: password
cherry@59.151.47.49's password:

解決方案

就我所遇到的情況來看, 顯然是要把 GSSAPI 停用. 以下是三種可行的方式:
[] 該解決方案是在客戶端 OpenSSH_4.7p1 Debian-8ubuntu1.2, OpenSSL 0.9.8g 下測試並透過的.
1. 連線時用命令指定:
ssh -o GSSAPIAuthentication=no cherry@59.151.47.49
2. 在 ssh 客戶端程式的配置檔案裡顯式停用 GSSAPI 認證. 如, 編輯 /etc/ssh/ssh_config 檔案, 新增或修改使其有如下一行:
GSSAPIAuthentication no
3. 在使用者根目錄下的 .ssh 目錄下建立一個 config 檔案. 如, 編輯 /home/cherry/.ssh/config (如果該檔案不存在, 則建立之), 新增選項:
GSSAPIAuthentication no
[] A. /etc/ssh/ssh_config 是全域性配置檔案, 對其進行的修改會影響所有使用 ssh 客戶端的系統使用者.
        B. /home/cherry/.ssh/config 是隻會影響使用者 xcl 的本地 ssh 客戶端配置檔案. 該檔案的所有配置引數會覆蓋全域性配置檔案的相同配置引數.
在停用 GSSAPI 後, ssh 的登陸提示 "迴歸" 正常了:
cherry@cherry:~$ ssh -v cherry@59.151.47.49
...
...
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/cherry/.ssh/identity
debug1: Trying private key: /home/cherry/.ssh/id_rsa
debug1: Trying private key: /home/cherry/.ssh/id_dsa
debug1: Next authentication method: password
cherry@59.151.47.49's password:
可見, 該過程已經不再使用 GSSAPI 了. 速度也大大提高了.

相關文章