To avoid ssh connection closing when we have not entered commands over long period of times, add the following line to the end of file /etc/ssh/ssh_config
ServerAliveInterval 60
The ssh client will send keep alives to the server and the ssh connection will not closed again.