While remotely connecting to a Linux machine using ssh, my .ksh session hangs after being inactive for sometime. If I try to type or ctrl-z, the prompt does not respond. Is there a way to restore my session?
What's probably happening is that some network equipment somewhere between the client and the server terminates connections that have been idle for a certain time. Such network equipment (firewalls, NAT appliances, …) often kills idle connections after a while to save memory (it's a defense against denial of service, but it does tend to be an annoyance to users).
To avoid this, you can set the
ServerAliveInterval option in
~/.ssh/config to a value that's lower than the timeout after which your connections get killed. For example, if your connections get killed when they've been idle for 10 minutes, set
ServerAliveInterval to 5 minutes:
Additionally, in case you do get cut off, use a terminal multiplexer on the server: Screen or tmux. For example, with Screen, run
screen -rd on the server when you log in; if you get disconnected, reconnect to the server and run
screen -rd to reattach to your existing session. See also and tmux vs. GNU Screen