How to increase SSH Connection timeout?

May 27, 2017 15.5k views
Linux Basics Ubuntu 16.04

Hi everyone! I have an issue about SSH connection.
Previously I set /etc/ssh/ssh_config as ConnectionTimeout 0 but still closes connection. So Am I missing something? How can I keep alive connection? What can I do anything else client-side? (I use Hyper.js on MacOSX) (Droplet: Ubuntu 16)

Edit: There is no timeout sFTP. While using Atom.

1 Answer
Mohsen47 May 27, 2017
Accepted Answer


/etc/ssh_config is the client side configuration file not the server side config file.

To prevent all your clients from timing out you need to edit /etc/sshd_config which is the server side configuration file add these two options:

ClientAliveInterval 120
ClientAliveCountMax 720

The first one configures the server to send null packets to clients each 120 seconds and the second one configures the server to close the connection if the client has been inactive for 720 intervals that is 720*120 = 86400 seconds = 24 hours

I hope this helps.

  • @selcukahmet @Mohsen47

    As a general note, you may also need to set these configuration options up on your end, as in on your MacBook. You can do this by creating a config file in ./ssh, i.e.:


    You can add:

    Host *
        ClientAliveInterval ...
        ClientAliveCountMax ...
        ServerAliveInterval ...

    Keep in mind, if you're MacBook goes in to sleep mode, you shut the lid, or a screensaver pops up, you may still end up with a closed connection.

Have another answer? Share your knowledge.