2

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?

11
  • 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, 2016 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, 2016 at 17:45
  • Not sure if shell 1 times out or drops the connection or is hung.
    – Plebeian
    May 24, 2016 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, 2016 at 17:47
  • Is there a way to estore and continue the session in shell 1 ?
    – Plebeian
    May 24, 2016 at 17:50

1 Answer 1

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .