SSH connection drops too frequently

October 13, 2019 358 views
CentOS

Hi guys,

So in the recent two days, I’ve come back to my projects. I left them for about a month or so. I noticed when I work on my droplet, my SSH connection is fine but if I leave if for more than 5 minutes, it just drops.

Can you guys assist me, is this something specific to Digital Ocean droplets?

2 Answers

Hi @Remdore ,

I can see this has been fully discussed HERE

To paraphrase, in order to keep your connection alive for more than the default time, some adjustments will be needed.

First, you’ll need to edit your sshd_config file.

vi /etc/ssh/sshd_config

Find the following lins and uncomment them

TCPKeepAlive
ClientAliveInterval
ClientAliveCountMax

Once you do, change their values to

TCPKeepAlive yes
ClientAliveInterval 30
ClientAliveCountMax 99999

Save the changes you’ve made and restart your sshd service

service sshd restart

Regards,
KDSys

  • I made the changes but I still seem to be experiencing the same problem.

    Should I provide my sshd_config? Or is it there another solution this.

    • It’s possible your NAT is dropping your TCP socket after a period of inactivity.

      Your ssh client can optionally send periodic reminders so to say to the server. To do this, add this the following to your ~/.ssh/config under Host *:

      ServerAliveInterval 80
      

      Let me know how this goes.

      Regards,
      KDSys

      • Thank you for the suggestion but won’t this actually cause somekind of load or strain on my server?

        If my local computer is sending out packages or whatever they are called this should be reflected on the system right?

        Thank you once again for the fast replies.

        • @Remdore, I understand where your concern is coming from but in this case nothing like that would happen.

          Let me provide you with more information to clear the uncertainty

          ServerAliveInterval The client will send a null packet to the server every 100 seconds to keep the connection alive

          NULL packet Is sent by the server to the client. The same packet is sent by the client to the server. A TCP NULL packet does not contain any controlling flag like SYN, ACK, FIN etc. because the server does not require a reply from the client.

          So basically the first settings you configured alongside the above, should be enough for this issue to be resolved.
          Regards,
          KDSys

Either you have made the changes that have lead to the issue or your hosting server. Contact the support team from your hosting site or visit their FAQs to know whether they have your answer.

Have another answer? Share your knowledge.