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?
-
It's not immediately clear if your *shell* is hung, or if you've lost your ssh session to your shell. Are you trying to troubleshoot this apparent hang, or for ways to maintain a remote session if/when your (ssh) connection drops? – Jeff Schaller May 24 '16 at 17:28
-
I login to an ssh session in shell 1, switch to shell 2 to do some piece of work there, come back to shell 1 after 15-20 mins and can't type anything in shell 1. I wish to maintain the remote connection in shell 1. – Plebeian May 24 '16 at 17:45
-
Not sure if shell 1 times out or drops the connection or is hung. – Plebeian May 24 '16 at 17:46
-
It sounds to me like you've lost your ssh connection. No characters show up in shell 1, and you haven't been returned to your pre-ssh prompt? – Jeff Schaller May 24 '16 at 17:47
-
Is there a way to estore and continue the session in shell 1 ? – Plebeian May 24 '16 at 17:50
-
Read *restore* in my previous comment. – Plebeian May 24 '16 at 17:51
-
How do I return to my pre-ssh prompt? – Plebeian May 24 '16 at 17:59
-
If the remote side hasn't closed the ssh connection, then use shell 2 to kill shell 1's ssh process. Does your remote shell have a TMOUT variable set? – Jeff Schaller May 24 '16 at 18:09
-
No. How can I find out about TMOUT? – Plebeian May 24 '16 at 18:16
-
ssh back in and run: echo $TMOUT – Jeff Schaller May 24 '16 at 18:17
-
Ran echo $TMOUT. Output is 0. – Plebeian May 24 '16 at 18:22
1 Answers
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:
ServerAliveInterval 300
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
- 807,993
- 194
- 1,674
- 2,175