7

i found that if my internet connection is disconnected during a ssh session to a remote Linux server, and then reconnect within a short time, the ssh session is still alive.

If I am running a program on the server and redirect its stdout and stderr outputs to a file, temporary internet disconnection doesn't seem to stop the program from running.

But will the disconnection affect the content of the file? I thought it wouldn't. I found some content of the file not repeatable when reruning the program without interruption to my internet connection, but I am not sure if the interruption to internet connection is the cause.

Tim
  • 101,790
  • 3
    One thing if you find your connect gets disrupted with some regularity you might want to use screen or tmux to protect your session. Then even if your connection goes away you can just relogin and connect again – Eric Renouf Jan 13 '16 at 18:54
  • The server runs Kerberos, so I don't know how to make screen and tmux work. – Tim Jan 13 '16 at 18:59
  • I've never tried it but https://uisapp2.iu.edu/confluence-prd/display/SOICKB/Understanding+Linux+Kerberos+Issues#UnderstandingLinuxKerberosIssues-persistent suggests running module load screen-kinit within screen so it will get its own ticket, though it will need to be renewed every so often if you want to leave it running for a long time – Eric Renouf Jan 13 '16 at 19:06
  • 1
  • This is not a duplicate of that question. It is not asking how to keep a program running. – Michael Homer Jan 13 '16 at 19:52

3 Answers3

8

If the session stays active then it stays active. There's no trickery there, just a buffer and TCP doing it's thing.

So if an connection to an ssh session is lost then recovered due to a "poor" internet connection, the app that is running in that session never knows. The session continues.

It's a lot like unplugging your monitor (while looking at the console) should not effect the app running on that console.

coteyr
  • 4,310
2

But will the disconnection affect the content of the file? I thought it wouldn't.

If the connection is interrupted, your session ends and your shell and command is killed. It you are interested in running commands on your remote server even if you disconnect, you should have a look for nohup command, screen or tmux multiplexor or mosh for poor connection shells.

Jakuje
  • 21,357
0

If you want to be certain your program remains running while disconnected, use screen. Then you can deliberately disconnect your ssh connection, come back hours or even days later and reconnect to it (so long as the machine hasn't rebooted, or anything else done to terminate the program, of course)