2021-05-12 14:32:11
Linux下SSH遠端連線服務慢解決方案
Linux下SSH遠端連線服務慢解決方案
1、適用命令及方案如下:
【遠端連線及執行命令】
ssh -p22 root@192.168.1.253
ssh -p22 root@192.168.1.253 /sbin/ifconfig
【遠端拷貝:推播及拉取】
scp -P22 -r -p /etc root@192.168.1.253:/tmp/
scp -P22 -r -p root@192.168.1.253:/tmp/ /etc
【安全的FTP功能】
sftp -oPort=22 root@192.168.1.253
【無密碼驗證方案】
例如利用sshkey批次分發檔案,執行部署操作。
2、連線慢的主要原因是DNS解析導致
解決方法:
最為常見的原因是因為server的sshd會去DNS查詢存取client IP的hostname,如果DNS不可用或者沒有相關記錄,就會耗費大量時間。
1、在server上/etc/hosts檔案中把你本機的IP和hostname加入
2、在ssh伺服器端上更改/etc/ssh/sshd_config檔案中的設定為如下內容:
UseDNS no
# GSSAPI options
GSSAPIAuthentication no
GSSAPIAuthentication引數是用於Kerberos驗證的,而對於絕大多數人來說,不可能使用這種驗證機制的,所以要注意把他們停掉。
然後,執行/etc/init.d/sshd restart重新啟動sshd進程使上述設定生效,在連線一般就不慢了。
3、如果還慢的話,檢查ssh伺服器端上/etc/hosts檔案中,127.0.0.1對應的主機名是否和
uname -n的結果一樣,或者把本機ip和hostname(uname -n結果)加入到/etc/hosts裡。
3、利用ssh-v的偵錯功能查詢慢的原因
其實可以用下面的命令偵錯為什麼慢的細節(學習這個思路很重要)。
[root@localhost ~]# ssh -v root@192.168.2.15
OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.2.15 [192.168.2.15] 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: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.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.2.15 (192.168.2.15)' can't be established.
RSA key fingerprint is ca:18:42:76:0e:5a:1c:7d:ef:fc:24:75:80:11:ad:f9.
Are you sure you want to continue connecting (yes/no)? yes
=======>這裡就是提示儲存金鑰的互動提示。
Warning: Permanently added '192.168.2.15' (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,password
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.2.15'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: Tue Sep 24 10:30:02 2013 from 192.168.2.13
在遠端連線時如果慢就可以確定卡在哪了。
[root@localhost ~]# ssh -v oldboy@192.168.2.18
OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.2.18 [192.168.2.18] 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 2
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
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
debug1: Host '192.168.2.18' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:2
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-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
上述設定沒配就發現卡到gssapi這。就大概知道是gssapi的問題。實際上在Linux系統優化部分就應該優化SSH服務的此處。
SSH服務遠端存取Linux伺服器登陸慢 http://www.linuxidc.com/Linux/2011-08/39742.htm
提高Ubuntu的SSH登陸認證速度的辦法 http://www.linuxidc.com/Linux/2014-09/106810.htm
開啟SSH服務讓Android手機遠端存取 Ubuntu 14.04 http://www.linuxidc.com/Linux/2014-09/106809.htm
如何為Linux系統中的SSH新增雙重認證 http://www.linuxidc.com/Linux/2014-08/105998.htm
在 Linux 中為非 SSH 使用者設定 SFTP 環境 http://www.linuxidc.com/Linux/2014-08/105865.htm
Linux 上SSH 服務的設定和管理 http://www.linuxidc.com/Linux/2014-06/103627.htm
SSH入門學習基礎教學 http://www.linuxidc.com/Linux/2014-06/103008.htm
SSH免密碼登入詳解 http://www.linuxidc.com/Linux/2015-03/114709.htm
本文永久更新連結地址:http://www.linuxidc.com/Linux/2015-05/117931.htm
相關文章