Question

SSH connection freezes

Hi,

My ssh connected terminal freezes after sometime (after being inactive for few minutes), I’ve changed the /etc/ssh/sshd_config to

TCPKeepAlive yes ClientAliveInterval 30 ClientAliveCountMax 99999

and restarted the ssh daemon service,

still it’s not working.

(I’m using Ubuntu 20.04 (LTS) x64)


Submit an answer
Answer a question...

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
September 22, 2021
Accepted Answer

Hi @thenishantgiri,

You’ll need to change the SSH settings on your local machine as well. To get your configuration working, make these configuration changes on the client:

/etc/ssh/ssh_config
Host *
ServerAliveInterval 100

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

KFSys
Site Moderator
Site Moderator badge
May 27, 2022

Hello all,

I know the question has been answered however here are a few more details on the matter.

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

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.