This question already has an answer here:

I've been looking around StackOverflow and it seems that SSH connections will disconnect when it doesn't see any packets for a while (2 hours?). Also, I looked in my /etc/ssh/ssh_config file and there doesn't seem to be anything there that would persist my current connection.

My question is: Even after 48 hours, why would an SSH connection persist? (my computer is turned off, but the server that I SSH to is presumably still online)

marked as duplicate by slm, Anthon, rahmu, Mat, Chris Down Aug 27 '13 at 2:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    Looking in the wrong file, KeepAlive is in sshd_config – Bratchley Aug 26 '13 at 1:32
  • Actually, it may last forever. – innocent-world Aug 26 '13 at 1:53
  • Are you saying an ssh session persists after turning the client off? – terdon Aug 26 '13 at 2:25
  • I've had idle sessions on ssh last for weeks - theoretically it's infinite. This is provided that there are no timeouts on the shell (in bash it has $TMOUT as an example), ClientAliveInterval is not being used in the sshd, your network connectivity stays stable and your client IP remains static. – Drav Sloan Aug 26 '13 at 2:41
  • You say your "computer is off and your server is presumably online" So what gives you the impression that the ssh connection still exists? – sambler Aug 26 '13 at 4:46

Maybe you have to set ClientAliveInterval in your sshd_config.


In theory, an SSH connection can last indefinitely. It can be explicitly terminated by either side at the SSH layer (with a FIN packet) or abnormally terminated at the TCP layer (with a RST packet).

A RST can happen if one side sends a packet and doesn't get a TCP acknowledgement in a reasonable amount of time. This usually happens because the other party is no longer there. It could also happen if there is a NAT or firewall in between that has stopped keeping track of the connection (usually due to lack of activity), so that the two parties can no longer communicate. More insidiously, a router at an evil ISP could inject RST packets into the connection, but such measures are usually reserved to content that the ISP finds objectionable, such as BitTorrent.

Keep-alives can help keep connections alive by reminding NATs or firewalls to maintain the connection state. However, keep-alives can also hurt by making it more likely that a transient glitch in network connectivity would be noticed.

Not the answer you're looking for? Browse other questions tagged or ask your own question.