While working on a remote machine through an SSH connection, your session might become unresponsive. That happens when you stop sending commands for some time and the server disconnects your SSH session.
You can stop SSH connection from timing out by configuring
ServerAliveInterval. This config sets an interval in seconds after which your SSH client sends a message to the server. By doing this, your session doesn’t become idle and remains connected.
~/.ssh/config and add the following configuration at the top.
You can adjust the number as you wish, but I have found values between 30 and 60 commonly used.