Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

From a Linux SSH shell, type /etc/init.d/network restart to restart the network service.

I expect my SSH connection to die since the network service goes down. But it doesn't. Very cool. But how does Linux achieve this? How does it keep my SSH connection alive across the service restart?

share|improve this question

migrated from stackoverflow.com Dec 25 '11 at 15:09

This question came from our site for professional and enthusiast programmers.

Good question. I always found this strange. – Saif Bechan Dec 25 '11 at 19:11

It does this by doing nothing special. The network restarts in less time than the TCP connection takes to time out, so the TCP connection survives the "outage" the same way it would survive any transient network outage.

The only reason Windows doesn't do the same thing is because Windows specifically resets TCP connections when a network interface goes down. This is, at least arguably, a pretty boneheaded thing to do because TCP was specifically designed to survive transient network outages.

share|improve this answer
David, then it means that the TCP/IP stack is not restarted, right? Because if it were, the server would have lost track of the SSH socket and the sshd child process (thanks Nils) would terminate. Which brings the next question: Which service manages the sockets? TIA. – Serge Wautier Dec 26 '11 at 8:04
+1 for saying Windows' implementation is "arguably boneheaded". – Kazark Dec 27 '11 at 3:40

SSHD forks a child process on connection. This child process will not die if either SSHD or the whole network is restarted. This is the reason why you can update ssh and/or its configuration, do a service sshd restart and still keep connected to your old ssh-session with the old settings. Apart from that ssh recovers well from small network outages.

share|improve this answer
SSH doesn't even know about 'small network outages', for the reason given by David Schwartz. It's not a property of SSH specifically. – EJP Dec 26 '11 at 21:40
I am not sure if there is not also a little bit of programming involved on the ssh-side. Basically all TCP services should be fault-tolerant - many are not. There needs to be an additional retry mechanism involved in the application - then the service can even survive "medium" outages as well. – Nils Dec 26 '11 at 21:59
As explained by EJP, your answer is true but irrelevant. – Gilles Dec 26 '11 at 23:21
This answer was useful to me because it added the insight about what sshd does to avoid going down on service sshd restart. If you update sshd (security update etc), the child processes would still be running on the original code (pre-update), but would continue to provide service, rather than being interrupted. I guess the availability of the listening socket for the main sshd process is very briefly interrupted, however, when the first child process ends and the network interface momentarily indicates the port as closed. – allquixotic Dec 14 '13 at 5:03
@allquixotic This interruption on restart does not matter for already existing connections - they stay connected. The "main" sshd listens then again for NEW incoming requests. Or with other words: upon fork the socket gets personalized as well for a specific connection. – Nils Dec 14 '13 at 22:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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