Solved SSH connection closes at seemingly random moments


Verified User
Sep 21, 2021
Een echte Hollander
Dear DirectAdmin forum,

Ever since an internet disruption at the office back in april, we keep getting disconnected randomly at SSH on every server every office computer connects to. This is what has happened:
  1. We've obtained a new IP address
  2. We get randomly disconnected somewhere between 1 to 5 minutes after the last keystroke or 1 to 5 minutes after starting a script
  3. Hitting any key resets this 1 to 5 minute timer
This manifests in the way that the terminal stops responding to our inputs. But it also doesn't signal that it has been disconnected. Sometimes the script we've started may still run, or it may not. This is completely random. We won't know unless we see the command being performed using "systemctl status | grep commandhere" in a new SSH connection.

The worst came to worst yesterday when attempting to perform "yum update" as the connection dropped while it was updating. "Sometimes" whatever script is running will still continue to run despite the connection already being gone for a couple minutes. This resulted in a slave NS to become unbootable after attempting to clean up the unfinished packages from this "yum update". Regardless of the methods I've used to do this, I had to revert its state 2 hours back. I made a backup at that point, attempted to do "yum update" again, this time spamming the letter y on the keyboard as it was performing the update - succesfully this time, after 10 minutes.

Looking up this issue online, I came up with the solution to keep the connection alive using "/etc/ssh/ssh_config.d/testconfig.conf"
ServerAliveInterval 60
ServerAliveCountMax 120

This did not in fact solve the issue. We are clueless about what we're supposed to do.

Servers from AND
All office computers have this problem
Connecting with any user, like root or userhere

Edit: image attached as the perfect example. The "update" command is a script that I've made called "update-the-server" and it goes through 5 commands, but already quit after using the "yum update -y" command on step 2. This notification only popped up after 15 or so minutes.


  • mRemoteNG_bmo6McBx0L.png
    43.4 KB · Views: 2
Last edited:
even you disconnect from terminal, "yum" still running in background. Just wait process finish.

you can read "yum" output by "/var/log/yum.log". it happend to me from time to time.

To ensure command must be execute in background,
just execute "yum update &"
I wish it was that simple, because that does not explain why some packages are updated and some are not as they are listed out and it just... stops. This not only applies to yum, this applies to every single command that takes longer than a minute. Even being connected for longer than a minute runs the risk of us being dropped. I am afraid to use any command which I know has the potential to take longer than a full minute for that reason alone + edit: especially as there's no guarantee the command actually fully completes its task.
There are too many things that could cause this. I had this issue years ago, and it was due to my home router timing the connection out, with no way to change that setting. My fix was to get a new router that I had more control over. Obviously you have a timeout setting somewhere between your computer and the destination network. The trick is to find where along that path the disconnect is happening.
ServerAliveInterval 60
ServerAliveCountMax 120

This did not in fact solve the issue. We are clueless about what we're supposed to do.
I had kind of like that too, but it's the client disconnecting.

I enabled it and changed the timing in the /etc/ssh/sshd_config file and now use these values:
ClientAliveInterval 120
ClientAliveCountMax 30

Didn't have issues anymore. Ofcourse adjust to your own needs.
Thank you for the reply @Richard G . This gave me a reminder that there was also a KeepAlive option in PuttyNG. I've now set and saved that option under the default settings, after which I didn't seem to have any problems anymore.

So thank you all for pointing me into the right direction. This was actually very helpful!