2

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)

ishikun
  • 143
  • 2
    Looking in the wrong file, KeepAlive is in sshd_config – Bratchley Aug 26 '13 at 01:32
  • Actually, it may last forever. – innocent-world Aug 26 '13 at 01:53
  • Are you saying an ssh session persists after turning the client off? – terdon Aug 26 '13 at 02: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 02: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 04:46
  • I'm using VNC viewer to view the server and I don't need to do a SSH beforehand. – ishikun Aug 26 '13 at 05:00
  • @JoelDavis Thanks very much, I found a 'TCPKeepAlive yes' in sshd_config! :) – ishikun Aug 26 '13 at 05:03
  • I don't definitely know, nor can anybody here, depends on a lot of things, networking, host problems at either end, timeouts put in firewalls or even timeouts in shells.......so this really is a useless question without definitive answers. – mdpc Aug 26 '13 at 06:21

2 Answers2

8

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.

200_success
  • 5,535
1

Maybe you have to set ClientAliveInterval in your sshd_config.

b166er
  • 141