Use -o ServerAliveInterval=60 option with ssh
Example:ssh -i <client-key> -o ServerAliveInterval=60 ubuntu@<IP address>
Useful link: https://www.quora.com/Why-does-ssh-to-amazon-ec2-instance-gets-frozen-after-sometime