国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

LinuxSSH登錄慢案例分析

2024-06-28 14:31:37
字體:
來源:轉載
供稿:網友

手頭有臺linux服務器ssh登錄時超級慢,需要幾十秒。其它服務器均沒有這個問題。平時登錄操作都默默忍了。今天終于忍不住想搞清楚到底什么原因。搜索了一下發現了很多關于ssh登錄慢的資料,于是自己也學著來分析、印證一下ssh登錄慢的原因。

出現ssh登錄慢一般有兩個原因:DNS反向解析的問題和ssh的gssapi認證

 

1:ssh的gssapi認證問題

GSSAPI ( Generic Security Services application PRogramming Interface) 是一套類似Kerberos 5 的通用網絡安全系統接口。該接口是對各種不同的客戶端服務器安全機制的封裝,以消除安全接口的不同,降低編程難度。但該接口在目標機器無域名解析時會有問題

默認情況下,GSSAPIAuthentication在服務器端和客戶端都激活的。如果DNS服務出現問題,那么登錄過程要等到DNS查詢超時后才能繼續,這就是為什么SSH登錄提示符要等很久才出現的原因。 為什么ssh登錄過程中要用到DNS解析服務呢?這個是GSSAPI認證方式需要的緣故。

所以在配置文件/etc/ssh/sshd_config(服務器)或/etc/ssh/ssh_config(客戶端)將參數GSSAPIAuthentication設置為no可以解決ssh登錄慢的問題。

 

2:DNS反向解析的問題

OpenSSH在用戶登錄的時候會驗證ip,它根據用戶的IP使用反向DNS找到主機名,再使用DNS找到IP地址,最后匹配一下登錄的IP是否合法。如果客戶機的IP沒有域名,或者DNS服務器很慢或不通,那么登錄就會很花時間。

 

問題分析:

首先可以在ssh命令后面加上“-v“ 參數,輸出debug信息定位問題。 具體操作為ssh -v root@serverip

[root@localhost ~]# ssh -v root@192.168.xxx.xxx
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.xxx.xxx [192.168.xxx.xxx] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
The authenticity of host '192.168.xxx.xxx (192.168.xxx.xxx)' can't be established.
RSA key fingerprint is 04:08:57:22:7e:8d:dc:d3:8e:91:20:d0:ba:d9:ed:78.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.xxx.xxx' (RSA) to the list of known hosts.
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
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
No credentials cache found
 
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Next authentication method: password
root@192.168.xxx.xxx's password: 
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Last login: Sun Sep  6 08:30:47 2015 from 192.168.7.222
[root@ceglnx01 ~]# 
 
 

clip_image001

從上面輸出信息看到有關于Unspecified GSS failure,于是我將/etc/ssh/sshd_config(服務器)或/etc/ssh/ssh_config(客戶端)將參數GSSAPIAuthentication設置為no,重啟了sshd服務,測試發現ssh登錄還是很慢。

[root@localhost ~]# service sshd status
 
openssh-daemon (pid 3594) is running...
 
[root@localhost ~]# service sshd restart
 
Stopping sshd: [ OK ]
 
Starting sshd: [ OK ]

那么原因應該是DNS反向解析的問題,關于DNS反向解析的問題有幾個解決方法:

1:在server上/etc/hosts文件中把常用的ip和hostname加入,然后在/etc/nsswitch.conf看看程序是否先查詢hosts文件

2:在server上/etc/ssh/sshd_config文件中修改或加入UseDNS=no。然后重啟sshd服務

我在/etc/ssh/sshd_config上將UseDNS設置為no,重啟sshd服務后,然后測試ssh連接速度。果然飛快連接上。看來主要還是DNS反向解析的問題。

 

參考資料:

http://www.linuxidc.com/Linux/2012-12/77144.htm

http://blog.chinaunix.net/uid-16728139-id-3435980.html


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 剑川县| 定远县| 正阳县| 山阳县| 登封市| 龙山县| 方山县| 峡江县| 科技| 阿克苏市| 雅江县| 红桥区| 讷河市| 远安县| 南华县| 松原市| 宜春市| 金寨县| 乐安县| 鱼台县| 赫章县| 营山县| 布尔津县| 永年县| 舟曲县| 沾益县| 綦江县| 漠河县| 金阳县| 汾西县| 攀枝花市| 寻甸| 金门县| 皮山县| 连云港市| 阳新县| 嘉兴市| 乌审旗| 体育| 乡城县| 蒙城县|