Inactive or idle SSH connections are normally disconnected by the server after a certain period of time. This depends on how the SSH server is configured, and upon disconnection the SSH client will be prompted with a message similar to the following;
Read from remote host oseems.com: Connection reset by peer Connection to oseems.com closed.
This could be avoided by changing the SSH server’s configuration, or tricking the server from the client’s end.
This is probably the easiest method as it doesn’t require
root or administrator access to the server and it could be applied to all SSH connections instead of just to a specific server.
What’s going to happen is to basically keep the connection active even if the user is actually idle. This could be done by using the
ServerAliveInterval option where the SSH client will send a null packet to the server over a set period of time just to keep the connection alive.
The following option will send the packet every 100 seconds;
In Linux this could be set globally in /etc/ssh/ssh_config or per-user in ~/.ssh/config. It could also be used in the command line as an argument as in the following example;
ssh -o ServerAliveInterval=100 firstname.lastname@example.org
With administrator / root access, the option could just be disabled in the server. Set the related options in the global SSHd configuration file as the following, and restart the SSHd service.
ClientAliveInterval 30 TCPKeepAlive yes ClientAliveCountMax 99999
/etc/ssh/sshd_config normally is the configuration file and the service could usually be restarted by the following command;
sudo service sshd restart