Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 a SSH connection persist? (my computer is turned off, but the server that I SSH to is presumably still online)

share|improve this question
2  
Looking in the wrong file, KeepAlive is in sshd_config –  Joel Davis 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
show 3 more comments

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 Answers

up vote 1 down vote accepted

Maybe you have to set ClientAliveInterval in your sshd_config.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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