Linux SSH登錄很慢的解決方法
使用ssh客戶端(如:putty)連接Linux服務(wù)器,可能會等待10-30秒才有提示輸入密碼。嚴(yán)重影響工作效率。登錄很慢,登錄上去后速度正常,這種情況主要有兩種可能的原因:
1. DNS反向解析問題
OpenSSH在用戶登錄的時(shí)候會驗(yàn)證IP,它根據(jù)用戶的IP使用反向DNS找到主機(jī)名,再使用DNS找到IP地址,最后匹配一下登錄的IP是否合法。如果客戶機(jī)的IP沒有域名,或者DNS服務(wù)器很慢或不通,那么登錄就會很花時(shí)間。
解決辦法:
在目標(biāo)服務(wù)器上修改sshd服務(wù)器端配置,并重啟sshd
vi /etc/ssh/sshd_config
UseDNS no
2. 關(guān)閉ssh的gssapi認(rèn)證
用ssh -v user@server 可以看到登錄時(shí)有如下信息:
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
注:ssh -vvv user@server 可以看到更細(xì)的debug信息
解決辦法:
修改sshd服務(wù)器端配置
vi /etc/ssh/ssh_config
GSSAPIAuthentication no
可以使用ssh -o GSSAPIAuthentication=no user@server登錄
GSSAPI ( Generic Security Services Application Programming Interface) 是一套類似Kerberos 5的通用網(wǎng)絡(luò)安全系統(tǒng)接口。該接口是對各種不同的客戶端服務(wù)器安全機(jī)制的封裝,以消除安全接口的不同,降低編程難度。但該接口在目標(biāo)機(jī)器無域名解析時(shí)會有問題
使用strace查看后發(fā)現(xiàn),ssh在驗(yàn)證完key之后,進(jìn)行authentication gssapi-with-mic,此時(shí)先去連接DNS服務(wù)器,在這之后會進(jìn)行其他操作
[root@192-168-3-40 ~]# ssh -vvv root@192.168.3.44
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 192.168.3.44 [192.168.3.44] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/identity-cert type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
debug3: Wrote 960 bytes for a total of 981
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-dss-cert-v00@openssh.com,ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_setup: found hmac-md5
debug1: kex: server->client aes128-ctr hmac-md5 none
debug2: mac_setup: found hmac-md5
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
debug3: Wrote 24 bytes for a total of 1005
debug2: dh_gen_key: priv key bits set: 120/256
debug2: bits set: 506/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug3: Wrote 144 bytes for a total of 1149
debug3: check_host_in_hostfile: host 192.168.3.44 filename /root/.ssh/known_hosts
debug3: check_host_in_hostfile: host 192.168.3.44 filename /root/.ssh/known_hosts
debug3: check_host_in_hostfile: match line 8
debug1: Host '192.168.3.44' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:8
debug2: bits set: 527/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: Wrote 16 bytes for a total of 1165
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug3: Wrote 48 bytes for a total of 1213
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /root/.ssh/identity ((nil))
debug2: key: /root/.ssh/id_rsa ((nil))
debug2: key: /root/.ssh/id_dsa ((nil))
debug2: key: /root/.ssh/id_ecdsa ((nil))
debug3: Wrote 64 bytes for a total of 1277
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup gssapi-keyex
debug3: remaining preferred: gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-keyex
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug2: we did not send a packet, disable method
debug3: authmethod_lookup gssapi-with-mic
debug3: remaining preferred: publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-with-mic
debug1: Next authentication method: gssapi-with-mic
debug3: Trying to reverse map address 192.168.3.44.
debug1: Unspecified GSS failure. Minor code may provide more information
Cannot determine realm for numeric host address</p> <p>debug1: Unspecified GSS failure. Minor code may provide more information
Cannot determine realm for numeric host address</p> <p>debug1: Unspecified GSS failure. Minor code may provide more information</p> <p>
debug1: Unspecified GSS failure. Minor code may provide more information
Cannot determine realm for numeric host address</p> <p>debug2: we did not send a packet, disable method
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/identity
debug3: no such identity: /root/.ssh/identity
debug1: Trying private key: /root/.ssh/id_rsa
debug3: no such identity: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug3: no such identity: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug3: no such identity: /root/.ssh/id_ecdsa
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
root@192.168.3.44's password:
相關(guān)文章

集成系統(tǒng)級Claw模式! Deepin 官宣發(fā)布 25.1 版本
deepin操作系統(tǒng)發(fā)布了最新的 25.1 版本更新,該版本基于 deepin 25 正式版積累的多輪內(nèi)測成果,在 AI 能力、內(nèi)核版本、桌面環(huán)境、文件管理器以及系統(tǒng)安全等方面進(jìn)行了更新2026-04-13
又一代老硬件退場! Linux 內(nèi)核正式放棄Intel 486 CPU
在過去的幾十年間,CPU 的架構(gòu)已經(jīng)經(jīng)歷了飛速發(fā)展,x86 系列就是其中之一,而 i486 則屬于該系列中的一個(gè),當(dāng)前,i486 的CPU處理器已經(jīng)夠老,從 Linux 7.1 開始將不再有對2026-04-09
趕緊收藏! 全網(wǎng)最全 Linux 命令總結(jié)
我把 Linux 中最常用、最實(shí)用、最常被問到的命令按照實(shí)際使用場景分類整理,方便你快速查閱和記憶,內(nèi)容覆蓋日常運(yùn)維、開發(fā)調(diào)試、性能分析、文件處理、網(wǎng)絡(luò)、安全、系統(tǒng)管2026-04-08
一分鐘內(nèi)檢查Linux服務(wù)器性能? 9個(gè)性能檢測常用的基本命令
今天我們來看看Linux系統(tǒng)中用于性能監(jiān)控的一系列命令,這些命令可以快速查看機(jī)器的負(fù)載情況,詳細(xì)請看下文介紹2026-03-18
從零基礎(chǔ)到精通! 適合高級用戶的15款Linux發(fā)行版推薦
Linux作為操作系統(tǒng)領(lǐng)域靈活性和可定制性的基石,提供了大量滿足不同用戶需求的發(fā)行版,今天分享適合高級用戶的15款Linux發(fā)行版2026-03-10
開箱即用? 這4個(gè)高手級Linux發(fā)行版遠(yuǎn)沒你想象的那么安全易用
如果你正在糾結(jié)用哪個(gè)發(fā)行版?零基礎(chǔ)新手別被“高端”“極客”“聲明式”這些詞沖昏頭腦,先用好用的,再慢慢進(jìn)階2026-03-10
這幾款SSH工具真的夠用了! Linux好用的ssh工具推薦
在Linux上使用SSH,您需要安裝一個(gè)SSH客戶端,今天整理找到的8 款 SSH / 終端工具,從免費(fèi)開源到企業(yè)級商用,從輕量化命令行到一站式工具箱,每款都做了介紹與對比,希望能2026-03-09
在Linux系統(tǒng)下有兩種用戶,即高級用戶root,普通用戶,高級用戶root可以在系統(tǒng)中做任何事情,普通用戶僅可在Linux系統(tǒng)中做有限的事情,下面我們就來看看切換方法2026-02-28
揭秘當(dāng)前登錄用戶的身份! Linux中使用logname命令的技巧
logname命令就是這樣一個(gè)簡單但強(qiáng)大的工具,它能幫助我們輕松獲取當(dāng)前登錄用戶的用戶名,今天,我們就來深入探索一下這個(gè)命令的工作原理、使用方法和最佳實(shí)踐2026-02-26
在 Linux 系統(tǒng)中,DNS 緩存是一種將域名和 IP 地址映射關(guān)系緩存在本地的機(jī)制,可以加快域名解析速度,并減輕 DNS 服務(wù)器的負(fù)載2026-02-26



