I am using Macbook developing a client application.

I want to access server logs, so I opened a shell terminal and established a ssh connection to the server and access the log file there by executing

tail -f server.log

It works, but the remote ssh session will expire after certain amount of time, which needs me to establish the ssh connection again and access the server log file again.

How can I keep the remote session all the time without expiration?

  • Not duplicate, but related: unix.stackexchange.com/questions/20193/…
    – depquid
    Apr 4, 2013 at 12:02
  • Is it dying after being idle a certain amount of time, or is it dying a certain amount of time after start whether idle or not?
    – phemmer
    Apr 4, 2013 at 13:43
  • If the cause of the problem is that your network connection is unreliable, you might consider mosh.
    – Chris Down
    Apr 7, 2015 at 16:44

2 Answers 2


If the log file has a stead flow of data and the connection drops, then the cause is either A. Your firewall has a maximum tcp session time. B. There is some kind of reset happening, such has a hiccup in the wifi.

If you control both sides, you can install mosh: http://mosh.mit.edu/ which will reconnect, even if you change IPs or put your computer to sleep.

On the other hand, if the flow of data has long pauses, then you may be hitting the max idle timeout. You can add this to your ~/.ssh/config

Host *
        TCPKeepAlive yes

Try the SSH configuration as suggested by Georgyo's answer. If that doesn't work you're likely running up against some kind of connection time limit imposed by a firewall somewhere. If that's the case and you have no way of removing the timeout you can try using something like screen to keep the process running even when your ssh session disconnects. I use BYOBU for nearly everything anyway.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .