Question

How to increase SSH Connection timeout?

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.


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.

Accepted Answer

@selcukahmet

/etc/ssh/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/ssh/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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi all,

A bit of an off-topic but while making changes to your SSH configuration, it could be a good idea to also take a look at this tutorial here on how to secure/harden your OpenSSH service:

https://www.digitalocean.com/community/tutorials/how-to-harden-openssh-on-ubuntu-18-04

The tutorial covers some useful security tips that you could do simply by taking advantage of the /etc/ssh/sshd_config configuration file.

Best, Bobby

On local computer add line on file /etc/ssh/ssh_config:

ServerAliveInterval 120

this option will ping the server every 120 seconds and keep you connected indefinitely.

I’m not sure if it’s an option for you, but an SSH connection with an active X11 tunnel will not close. If you run nautilus or gedit or something through an X11 connection you won’t have this problem.