SSH Connection takes long time? Here are few fixes

Updated on June 3, 2021

Question: Why does SSH connection takes long time to connect to a machine in the same network? The password prompt takes long time to appear. However, I’m able to connect to other machines on the same network faster. What could be the reason? –  Gouri

debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mi c,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
Cannot determine realm for numeric host address

debug1: Unspecified GSS failure. Minor code may provide more information
Cannot determine realm for numeric host address

debug1: Unspecified GSS failure. Minor code may provide more information

debug1: Unspecified GSS failure. Minor code may provide more information
Cannot determine realm for numeric host address

debug1: Next authentication method: publickey
debug1: Trying private key: /home/gouri/.ssh/id_rsa
debug1: Trying private key: /home/gouri/.ssh/id_dsa
debug1: Trying private key: /home/gouri/.ssh/id_ecdsa
debug1: Next authentication method: password

Why does SSH Connection prompt takes long time to appear?

If you are able to connect to other machines in the same network without delay, then the issue is very specific to a particular machine. A quick look at the verbose output of SSH connection would give you lot of information.

According to the verbose output, SSH tries to authenticate using following methods.

publickey,gssapi-keyex,gssapi-with-mic,password

Following messages says that SSH failed to connect using gssapi-keyex, gssap-with-mic, publickey and finally it relied on password based authentication. Hence the password prompt appeared only after other authentication methods had failed.

If you are relying on password based authentication, then you may go ahead and disable other authentication mechanisms.

Disable GSSAPIAuthentication

Open the sshd_config file in the target machine and change GSSAPIAuthentication yes to no.

# vim /etc/ssh/sshd_config

GSSAPIAuthentication no

Save the changes and restart the SSH daemon.

# systemctl restart sshd

Still having ssh login delays? Probably you should try disabling UseDNS option in sshd_config file.

UseDNS is set to 'yes‘ by default which determines whether IP address to hostname lookup and comparison is performed. This setting could cause login delays and you may turn it off by setting ‘no

UseDNS no

Remember to restart the SSH daemon.

Was this article helpful?

Related Articles

Leave a Comment