Quick Fix: ssh timeouts


It is very annoying when you leave an ssh window open to your server with something running, go to lunch, come back to see this:

Read from remote host my.stupid.server.uni.edu: Connection reset by peer.
Connection to  my.stupid.server.uni.edu closed.


So here are two fixes. The first is server side.

  1. ssh to your server, and as root or sudo edit the file /etc/ssh/sshd_config then add the line:
    ClientAliveInterval 60

    This will send a timeout signal to the client every 60 seconds. The client (your desktop/laptop) is expected to be alive and answer. If it does, all is well. If not, the signals will continue every 60 seconds until a maximum count is reached (default is 3). Then the server will disconnect. So: if your client is connected and live, even if it is idle, this line in /etc/ssh/sshd_config will ensure no timeout happens. The maximum count can be set with:
    ClientAliveCountMax 3 (default is 3). But you don’t really need to do that. You will now need to restart your ssh server:

    sudo /etc/ssh/ssh restart


    sudo service ssh restart
  2. Alternatively, on the client side (your own desktop/laptop) edit the /etc/ssh/ssh_config (again, as root or sudo) and add the following line:
    ServerAliveInterval 60

    This is good for when you either don’t have root on your server, or you just don’t want to mess around with configuration files on the server itself.

Happy ssh-ing!



Share and Enjoy:
  • Fark
  • Digg
  • Technorati
  • del.icio.us
  • StumbleUpon
  • Facebook
  • Reddit
  • Twitter
  • FriendFeed
  • PDF
  • email
  • Print
  • Google Bookmarks

4 Responses to “Quick Fix: ssh timeouts”

  1. Nick says:

    Another option is to run the long-running program under “screen”. That way you can even log out while it’s running if you choose. I have no connection to the following link, but it seems to be a decent tutorial on this approach:

  2. Iddo says:

    Thanks for that, Nick. I did not know about screen. Seems to come as a default with Ubuntu (>=9.10).



  3. brent says:

    Thanks. I always have to look this up when setting up a new machine.

  4. I keep emacs open when I have a long-running job (which I put in the background anyway). The clock update in emacs keeps the ssh connection alive.