Question

How to keep SSH connection alive longer

I’ve followed the instructions in the 2 questions below:

https://www.digitalocean.com/community/questions/ssh-connection-drops-too-frequently https://www.digitalocean.com/community/questions/keep-my-ssh-session-alive

Despite this, my SSH connection drops extremely frequently, often after less than a minute of inactivity. When the connection drops, the terminal window freezes and I have to close it and open a new one. I know that the user session is kept alive for a while by the host.

Any suggestions beyond:

ClientAliveInterval 30 TCPKeepAlive yes ClientAliveCountMax 99999

and restarting the daemon?

Connecting from macOS Big Sur using iterm 2. Connections to other machines (not Digital Ocean) absolutely normal.

Show comments

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.

Hi @atjbramley,

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