Home » , » How to prevent SSH terminal timeout

How to prevent SSH terminal timeout

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. Annoying isn’t it? Here I will tutor how to avoid ssh timeout.
Read from remote host ocaoimh.ie: Connection reset by peer
Connection to ocaoimh.ie closed.
There’s a quick fix for that. Actually, 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.
  • On the server, login as root and edit /etc/ssh/sshd_config and add the line:
    ClientAliveInterval 60
    According to man sshd_config, this line,
    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.
  • 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:
    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.


Popular Posts