SSH slow login can be a result of recent network changes. If your SSH connection was ok before, and now takes a lot longer. The problem is either with your network or the terminal you try to using SSH protocol from. You can also try to login to the terminal from the localhost. Both can be tedious to fault find.
SSH slow login
Here is what happened to me, and how I fixed it. One day all my servers at home suddenly took 10-15 seconds or longer to connect to with SSH. My external servers behaved normally. So I knew it wasn’t my laptop. Also, all my servers, both at home and externally, is running Debian. Various versions of Debian, but only Debian.
My local internet provider has these really crappy fiber cable modems. Extremely limited settings and general bad quality with its built-in wifi too. I eventually got a decent Asus wifi router but had to move my servers at home to a different subnet. That resulted in ssh login takes very long time. It was not a slow ssh connection, just login to ssh was slow.
I configured the network interface changes, but that did not change anything (except the internet connection). I checked the OpenSSH log. That didn’t give anything away either. Then I noticed the nameserver address in the resolv.conf file. It was set to the old subnet. Here is how my resolv.conf file looks:
After I changed the nameserver over to the new subnet for the Asus router it works like before. Lightning quick login to ssh. Just like before I installed the new router. Because of some stupid limitations in the fiber cable modem, I really had to create a new subnet for the home servers.
Wrong nameserver setting is not the only reason for ssh slow login. There can be other reasons for ssh slow login too. It can also be a good idea to check the configuration for the host in the hosts file.
Some have fixed the issue by setting UseDNS setting to no in the ssh config (sshd_config). Like this:
sudo vim /etc/sshd_config
That will just disable the DNS for the secure shell server. I think just setting the correct nameserver address will be a better solution. Especially if a slow ssh login is a problem when connecting from an ssh client.
Other have solved slow ssh connection issues by disabling the GSSApi authentication. GSSAPI is a framework for authentication. You could try that too if none of the above worked out for your server. You disable the GSSAPI authentication in the sshd_config file.
sudo vim /etc/sshd_config
If none of the tips above helps. Try adding the -v argument when trying to connect to your ssh server. It will print out everything that is going on, and you can see where it hangs. If it is the nameserver settings that is wrong, it will look like the picture below.
After doing these changes a restart is recommended.
If you enjoyed my ssh slow login article you can check out my SSH login message change here. Or how to use the SCP command. An excellent method to transfer files with an encrypted connection on port 22.
Check out the OpenSSH documentation here.