Search code examples
sshputtyportforwardingplink

Enable keepalives in Plink


We are using Plink for a tunnel to a MySQL. We are using it in this format:

plink.exe -L [Port of our client]:[my-sql server host name]:3306 [bridge server ssh username]@[bridge server IP] -i [private key]

We cannot find an option to prevent the connection to be closed, a sort of keepalive.

How could we achieve this?


Solution

  • Instead of a keepalive that plink manages internally, another option is to use the shell that is created on the host to keep sending short bits of data on the wire. This can be done through a very simple shell script such as:

    while true;
    do echo 0;
    sleep 30s;
    done
    

    This very simple bash script will write the character 0 every 30 seconds to the screen.

    A full example of the whole command line when invoking plink:

    plink -P 443 [user@]host.com -R *:80:127.0.0.1:80 -C -T while true; do echo 0; sleep 30s; done