assume I have a ssh session to a remote host like ssh user@host tail for example and now somehing causes that host to reboot. How can I configure the session to terminate immediately and return back to shell? (To attempt reconnection in a while loop w/o user input) Thanks

  • Is that not the default behaviour?
    – user147505
    Jun 20, 2019 at 22:37
  • @Tomasz no, it takes quite a while until it finally disconnects and terminates the session.... :( - if the session has no active I/O anyways and just sits there...
    – stdcerr
    Jun 20, 2019 at 23:03
  • Possible duplicate of After sending shutdown command, ssh session doesn't terminate
    – user147505
    Jun 20, 2019 at 23:10
  • Ok, but which Linux then?
    – user147505
    Jun 20, 2019 at 23:39
  • Set ServerAliveInterval and ServerAliveCountMax to suitable values in your ~/.ssh/config file or by using -o options on the ssh command line. See man ssh_config for details. Jun 20, 2019 at 23:40

1 Answer 1


@cerr autossh can help you do that. It has a feature to start a copy of ssh and monitor it, then restarting it in case of stop passing traffic, server destination reboot. See more here.

also you should be used tmux or screen to create and keep the tty session on server destination, and combine them with autossh. In autossh documentation, they recommend that we should work together with screen for perpetual session.

  • Tien - Thanks,m i've uysed autossh before - for different purposes though but I'm well familiar wirth it, I also know and use both, screen and tmux - wouldn't want to live without them! ;)
    – stdcerr
    Jun 21, 2019 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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