How can I prevent ssh timeouts

I have a remote tunnel set up using this:

ssh -R 2022:127.0.0.1:2222 -N -f [email protected] -i .ssh/djangoserver

The remote machine can SSH successfully but the connection only lasts about 10 minutes before it either times out or locks up.

The keyboard does not respond and I have to kill the session on the remote machine then login again after that I cannot connect to the local machine


Solution 1:

Your post does not contain information why the connection timeout happens. If the server terminates the connection because the client was silent for too long, you can set the ServerAliveInterval.

From the man page

Sets a timeout interval in seconds after which if no data has been received from the server, ssh(1) will send a message through the encrypted channel to request a response from the server. The default is 0, indicating that these messages will not be sent to the server.

The configuration for this goes into $HOME/.ssh/config. If you want to send the signal every minute to the remote host example.net, put the following in the configuration file:

Host example.net
    HostName example.net
    ServerAliveInterval 60

You can enable it for all host if you use a wildcard

Host *
    ServerAliveInterval 60