<Enter>~.
The section “ESCAPE CHARACTERS” in the ssh man page explains the underlying details
Add the following to your ~/.ssh/config
:
Host remotehost
HostName remotehost.com
ServerAliveInterval 240
ServerAliveInterval
: Pings server every 4 minutes