It can be quite annoying to kill a frozen ssh session and the restart it. This can happen if you leave an ssh shell idle for too long. Your context and history is also lost on the target machine. Here are quick steps to prevent ssh disconnection due to timeout.
Using ServerAliveInterval in .ssh/config
Open ~/.ssh/config file and add the following line in the beginning:
This will send a null packet to server in case client is idle. Note that we can set ServerAliveInterval for a specific host also as shown below:
Host host1.com ServerAliveInterval 100
Using ServerAliveInterval option on command line
We can also set ServerAliveInterval on command line. Here is how you can set it:
ssh -o ServerAliveInterval=100 -l user1 server.com