Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: SSH Slowness.!!  (Read 2710 times)

0 Members and 1 Guest are viewing this topic.

Givin Varghese

  • Guest
SSH Slowness.!!
« on: November 17, 2013, 02:36:40 am »
Delay in SSH is a common issue in the Linux servers and here are some fixes I successfully tested. SSH delay is somewhat common for recent Centos 6 server, where you can try the following solutions.
Case 1::
When debug the SSH connection using -v, we can understand where exactly the require time to connect via SSH::Let us check this case.
Code: [Select]
[givin@server ~]#  ssh root@2xx.xx6.x4.1xx -v
OpenSSH_5.3p1 Debian-3ubuntu7, OpenSSL 0.8.2t 23 Mar 2006
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 2xx.xx6.x4.1xx [2xx.xx6.x4.1xx] port 22.
debug1: Connection established.
debug1: identity file /home/givin/.ssh/identity type -1
debug1: identity file /home/givin/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/givin/.ssh/id_dsa 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.3p1 Debian-3ubuntu7
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 '2xx.xx6.x4.1xx' is known and matches the RSA host key.
debug1: Found key in /home/givin/.ssh/known_hosts:164
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
debug1: An invalid name was supplied
Cannot determine realm for numeric host address


debug1: An invalid name was supplied
Cannot determine realm for numeric host address


debug1: An invalid name was supplied


debug1: Next authentication method: publickey
debug1: Trying private key: /home/givin/.ssh/identity
debug1: Offering public key: /home/givin/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /home/givin/.ssh/id_dsa
debug1: Next authentication method: password
root@2xx.xx6.x4.1xx's password:

In the above debugging process, we could understand that the time more consumed was during the below authentication.
Quote

debug1: Next authentication method: gssapi-with-mic
debug1: An invalid name was supplied
Cannot determine realm for numeric host address


debug1: An invalid name was supplied
Cannot determine realm for numeric host address


debug1: An invalid name was supplied

That is the server took time to authenticate during “gssapi-with-mic”. It’s clear that it’s trying to authenticate using GSSAPI (Kerberos), failing, then moving on to public key auth.
Well, the above issue can be resolved in three ways::


(1) It is understood from the above statement that disabling GSSAPI will definitely be one way. Yes, it is. Just explicitly disable GSSAPI authentication in the file /etc/ssh/sshd_config
Code: [Select]
[givin@server ~]# vim /etc/ssh/sshd_configthen find the line
Code: [Select]
GSSAPIAuthentication yeschange it to
Code: [Select]
GSSAPIAuthentication noand save the file. Then restart the sshd service.
Code: [Select]
[givin@server ~]# service sshd restartYou are done. Now logout and test the ssh connection using -vv and feel the difference :)


(2) Second method is without disabling the GSSAPIAuthentication permanently, but if you ask me, a bit tedious one. ;)
Code: [Select]
[givin@home ~]#  ssh  -o GSSAPIAuthentication=no root@23.226.134.152 -vYou can use the same for the scp also.


(3) The third method is by creating a file in the .ssh directory of the home directory of the user. Then add the line GSSAPIAuthentication no in that file and save it.
Code: [Select]
[givin@server ~]#cd ~/.ssh
[givin@server .ssh]#vim config
add this line
Code: [Select]
GSSAPIAuthentication no
save and exit
Then restart the sshd service.
Code: [Select]
[givin@server ~]# service sshd restartWell, I am not sure the third fix work or not (didn't work for me...LOL), anyway I am sharing it for the sake of sharing..he he  ;D ;D 8)
What is GSSAPIAuthentication and what does it do?
GSSAPI stands for Generic Security Services API. Just like its name suggests is a API that provides a standard interface for communicating with different protocols. GSSAPI is a ITEF standard for doing strong encrypted authentication in network based applications.
In SSH's case its designed to talk to Kerberos. But in case of Windows it can be made to talk to NTLM.
So what actually happens when SSH communication is initiated? If you debug the connection you'll see something like this:
Quote
debug3: preferred gssapi-keyex,gssapi-with-mic,gssapi,publickey,keyboard-interactive,password

The server offers 'gssapi-keyex' as a possible authentication and the client tries to authenticate against it. With the options listed above we just turn GSSAPI based authentication off on the client side. But a better solution, in case that you are not using this authentication at all, is to turn it off on the server side in /etc/ssh/sshd_config.


Case 2::
Before proceeding to case 2, please note that if the issue showing is with GSSAPIAuthentication, then you must disable it to speed up the ssh connection.
There is an option in the /etc/ssh/sshd_config called UseDNS, we can simply disable this option by following the below commands to speed up the ssh connection to a remote server.
Code: [Select]
[givin@server ~]# grep UseDNS /etc/ssh/sshd_config
UseDNS yes
If it displays like this, then we need to edit it to or comment that line.
Code: [Select]
UseDNS no
What is UseDNS for?
Enabling this makes access from a location without proper (forward and reverse) DNS generate a warning in the logs. It would need some qualified remote address of the client in order not to log any warning. Such a warning may help you in tracing down the attacker only if that PTR record makes any sense.


Case 3::
Third way is to add a single line in the /etc/resolv.conf file::options single-request-reopen
Code: [Select]
[givin@server ~]# vim /etc/resolv.conf
options single-request-reopen
save and exit
What "single-request-reopen" do?
The resolver uses the same socket for the A and AAAA requests.  Some hardware mistakenly sends back only one reply.  When that happens the client system will sit and wait for the second reply.  Turning this option on changes this behavior so that if two requests from the same port are not handled correctly it will close the socket and open a new one before sending the second request.



Enjoy the SpEed 8) :o ;D :D ;) :-* :-X 8) :o ;D