Append this option to ssh command to prevent the server closing the connection

-o ServerAliveInterval=100