How to fix timeout issue with SSH in Linux

Linux OS Topics
Post Reply
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

How to fix timeout issue with SSH in Linux

Post by Saman » Tue Jun 01, 2010 5:55 pm

If you use ssh a lot, you may have noticed that your ssh session times out and you’re logged out every once in a while.
Read from remote host robot.lk: Connection reset by peer
Connection to robot.lk closed.
There are 2 ways to fix it. You only need to do one of them so choose whichever one is easiest for you. You’ll need root access, so for most people it’s probably safer to do the client fix rather than the server fix.
  1. On the server, login as root and edit /etc/ssh/sshd_config and add the line:

    Code: Select all

    ClientAliveInterval 60
    This sets a timeout interval in seconds after which if no data has been received from the client, sshd(8) will send a message through the encrypted channel to request a response from the client. The default is 0, indicating that these messages will not be sent to the client. This option applies to protocol version 2 only.

    Don’t forget to restart sshd on the server after you save the file.
  2. The other way, and easier and safer way is for your desktop machine to send those keep alive messages. As root on your desktop (or client) machine, edit /etc/ssh/ssh_config and add the line:

    Code: Select all

    ServerAliveInterval 60
    That will send send a message to the server every 60 seconds, keeping the connection open. I prefer this way because I login to several machines every day, and I don’t have root access to all of them.
Post Reply

Return to “Linux”