SSH Login Takes a Long Time

Has it ever happened to you that logging in to an SSH server takes a long time? More than, say 20, 30 seconds? Well, there are many solutions out there to fix it, some may even make your system less secure. So let’s go to the source of SSH, so to speak, for a resolution. If you head over to ssh(1) takes a long time to connect or log in, you will see that it’s an issue with DNS resolution. To resolve this issue, try the following steps:

You need to change the sshd config file (on the server) …

sudo vim /etc/ssh/sshd_config

… and make sure you have this line uncommented

UseDNS no

Save the file and restart SSH daemon (service) like so

sudo service sshd restart (Fedora, Red Hat, CentOS)


sudo /etc/init.d/sshd restart (Debian, Ubuntu)

Hat tip: Slow SSH login;

14 Responses to SSH Login Takes a Long Time

  1. Joel says:

    Or, you could just, um, fix your broken dns?

  2. q says:

    You do this on the ssh server, or on the client machine that you use to login?

  3. hs says:

    I have updated the post to reflect q’s question: you have to do this on the server.

  4. Gugan says:

    This works, great fix. Appreciated

  5. Dan says:

    Thanks, This fixed the issue for now, although there wasn’t a “UseDNS” option in the config.

    I just added it to the end of the file, restarted sshd and this worked fine.

  6. Elia says:


  7. Deter says:

    Yep, it works! My ssh login delay was few seconds, but adding the line
    UseDNS no
    speeds it up to less then one second.
    Many thanks ;)

  8. chok says:

    Thanks – fixed my slow login. Also for me (Debian wheezy) that option was not in the file to uncomment, but it is in the man page.

  9. nigelhorne says:

    Joel’s comment is correct, though rather bluntly worded. What you need to do is to fix your reverse DNS. A great place to find out how to implement reverse DNS is at It fixed my problem and I suggest you use it on your machine rather than turning off DNS in SSH (it is on by default for a good reason).

  10. chok says:

    nigelhorne: I completely agree. I was having this problem when using ssh to connect from temporary virtual machines and I just did not bother to put them in DNS. Now that everything is stable, I have DNS working and I have changed my sshd_config file to “UseDNS yes”.

  11. dobbtown_fugitive says:

    Thank you, nigelhorne. That was a very helpful and informative link.

  12. Wolfgang says:

    For those not happy with this solution, like myself at first, try to synchronize clocks (ntp) prior of sshd restart, especially if your machine is part of an AD domain.

  13. kamyk says:

    Great, this works for my local system, now its much faster to get any response via php NET_SSH2, thank you very much!!!

%d bloggers like this: