1) Open the ssh_config file.
location may differ,in centos
vim /etc/ssh/ssh_config
2) Add following lines
Host *
ServerAliveInterval 300
ServerAliveCountMax 2
Remember, this configuration is done at client side. client send keep alive message to server every 180 seconds and server send ack (acknowledgement) message.If 2 consecutive ack messages are lost from server side. connection will be dropped as server is not available.