Question

SSH connection drops too frequently

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?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
October 13, 2019
Accepted Answer

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

KFSys
Site Moderator
Site Moderator badge
May 27, 2022

Hello all,

I’m giving an updated answer on the question so that it’s easier to follow:

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

You need to edit your local SSH config as well. You’ve finished the first part with the questions you’ve provided.

What you need to do is add

  1. ServerAliveInterval 30

locally.

There a couple of ways to do so. You can add it in the /etc/ssh/ssh_config file like so

  1. ServerAliveInterval 10

or in your .ssh/config file:

  1. Host *
  2. ServerAliveInterval 10

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.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.