open the file /etc/ssh/sshd_config on the virtual machine
add the lines at the end of the file
ClientAliveInterval 50
ClientAliveCountMax 10
restart the service or reboot the system
sudo service ssh restart
The other way is to keep any server alive by changing the ssh configuration on the client machine or local machine. To do it for all users in the local machine open the file
sudo vi /etc/ssh/ssh_configadd the following line under the host * section:
ServerAliveInterval 50