Solution to slow centos SSH remote connection
The primary cause of slow connection is DNS resolution.
Solution:
1. Change the configuration in the/etc/ssh/sshd_config file on the ssh server as follows:
UseDNS no
# GSSAPI options
GSSAPIAuthentication no
Then, run the/etc/init. d/sshd restart command to restart the sshd process to make the above configuration take effect. The connection is generally not slow.
If it is still slow, check whether the host name corresponding to 127.0.0.1 and
The uname-n results are the same, or you can add the local ip address and hostname (uname-n results) to/etc/hosts.
[Python] view plaincopy
- [Root @ C64 ~] # Uname-n
- C64
- [Root @ C64 ~] # Cat/etc/hosts
- # Modibyoldboy11: 122013/9/24
- 127.0.0.1C64localhostlocalhost.localdomainlocalhost4localhost4.localdomain4
- : 1localhostlocalhost. localdomainlocalhost6localhost6. localdomain6
- 10.0.0.18C64
- ################
Use the ssh-v debugging function to find the cause of slowness
In fact, you can use the following command to debug the slow details (learning this idea is very important ).
[Python] view plaincopy
- [Root @ C64 ~] # Ssh-vroot @ IP Address
- OpenSSH_5.3p1, OpenSSL1.0.0-fips29Mar2010
- Debug1: Readingconfigurationdata/etc/ssh/ssh_config
- Debug1: Applyingoptionsfor *
- Debug1: Connectingto10.0.0.19 [10.0.0.19] port22.
- Debug1: Connectionestablished.
- Debug1: permanently_set_uid: 0/0
- Debug1: identityfile/root/. ssh/identitytype-1
- Debug1: identityfile/root/. ssh/id_rsatype-1
- Debug1: identityfile/root/. ssh/id_dsatype-1
- Debug1: Remoteprotocolversion2.0, remotesoftwareversionOpenSSH_4.3
- Debug1: match: OpenSSH_4.3patOpenSSH_4 *
- Debug1: Enablingcompatibilitymodeforprotocol2.0
- Debug1: LocalversionstringSSH-2.0-OpenSSH_5.3
- Debug1: SSH2_MSG_KEXINITsent
- Debug1: SSH2_MSG_KEXINITreceived
- Debug1: kex: server-> clientaes128-ctrhmac-md5none
- Debug1: kex: client-> serveraes128-ctrhmac-md5none
- Debug1: SSH2_MSG_KEX_DH_GEX_REQUEST (1024 <1024) sent
- Debug1: expectingSSH2_MSG_KEX_DH_GEX_GROUP
- Debug1: SSH2_MSG_KEX_DH_GEX_INITsent
- Debug1: expectingSSH2_MSG_KEX_DH_GEX_REPLY
- Theauthenticityofhost '10. 0.0.19 (10.0.0.19) 'can' tbeestablished.
- RSAkeyfingerprintisca: 18: 42: 76: 0e: 5a: 1c: 7d: ef: fc: 24: 75: 80: 11: ad: f9.
- Areyousureyouwanttocontinueconnecting (yes/no )? Yes
- ======> Here is the interaction prompt for saving the key.
- Warning: Permanentlyadded '10. 0.0.19 '(RSA) tothelistofknownhosts.
- Debug1: ssh_rsa_verify: signaturecorrect
- Debug1: SSH2_MSG_NEWKEYSsent
- Debug1: expectingSSH2_MSG_NEWKEYS
- Debug1: SSH2_MSG_NEWKEYSreceived
- Debug1: SSH2_MSG_SERVICE_REQUESTsent
- Debug1: SSH2_MSG_SERVICE_ACCEPTreceived
- Debug1: Authenticationsthatcancontinue: publickey, password
- Debug1: Nextauthenticationmethod: publickey
- Debug1: Tryingprivatekey:/root/. ssh/identity
- Debug1: Tryingprivatekey:/root/. ssh/id_rsa
- Debug1: Tryingprivatekey:/root/. ssh/id_dsa
- Debug1: Nextauthenticationmethod: password
- Root@10.0.0.19 'spassword:
- <Strong >=====> here is the interaction prompt prompting you to enter the password. </Strong>
- Debug1: Authenticationsucceeded (password ).
- Debug1: channel0: new [client-session]
- Debug1: Enteringinteractivesession.
- Debug1: Sendingenvironment.
- Debug1: SendingenvLANG = en_US.UTF-8
- Lastlogin: TueSep2410: 30: 022013from10. 0.0.18
- <Strong> If the remote connection is slow, you can determine where the connection is located. </Strong>
- [Root @ C64_A ~] # Ssh-voldboy @ IP Address
- OpenSSH_5.3p1, OpenSSL1.0.0-fips29Mar2010
- Debug1: Readingconfigurationdata/etc/ssh/ssh_config
- Debug1: Applyingoptionsfor *
- Debug1: Connectingto10.0.0.17 [10.0.0.17] port22.
- Debug1: Connectionestablished.
- Debug1: permanently_set_uid: 0/0
- Debug1: identityfile/root/. ssh/identitytype-1
- Debug1: identityfile/root/. ssh/id_rsatype-1
- Debug1: identityfile/root/. ssh/id_dsatype2
- Debug1: Remoteprotocolversion2.0, remotesoftwareversionOpenSSH_5.3
- Debug1: match: OpenSSH_5.3patOpenSSH *
- Debug1: Enablingcompatibilitymodeforprotocol2.0
- Debug1: LocalversionstringSSH-2.0-OpenSSH_5.3
- Debug1: SSH2_MSG_KEXINITsent
- Debug1: SSH2_MSG_KEXINITreceived
- Debug1: kex: server-> clientaes128-ctrhmac-md5none
- Debug1: kex: client-> serveraes128-ctrhmac-md5none
- Debug1: SSH2_MSG_KEX_DH_GEX_REQUEST (1024 <1024) sent
- Debug1: expectingSSH2_MSG_KEX_DH_GEX_GROUP
- Debug1: SSH2_MSG_KEX_DH_GEX_INITsent
- Debug1: expectingSSH2_MSG_KEX_DH_GEX_REPLY
- Debug1: Host '10. 0.0.17 'isknownandmatchestheRSAhostkey.
- Debug1: Foundkeyin/root/. ssh/known_hosts: 2
- Debug1: ssh_rsa_verify: signaturecorrect
- Debug1: SSH2_MSG_NEWKEYSsent
- Debug1: expectingSSH2_MSG_NEWKEYS
- Debug1: SSH2_MSG_NEWKEYSreceived
- Debug1: SSH2_MSG_SERVICE_REQUESTsent
- Debug1: SSH2_MSG_SERVICE_ACCEPTreceived
- Debug1: Authenticationsthatcancontinue: publickey, gssapi-keyex, gssapi-with-mic, password
- Debug1: Nextauthenticationmethod: gssapi-keyex
- Debug1: NovalidKeyexchangecontext
- Debug1: Nextauthenticationmethod: gssapi-with-mic
If the above configuration is not configured, It is found to be stuck in gssapi. It is probably a problem with gssapi.
In fact, the SSH service should be optimized in the linux system optimization section.