Persistent SSH Connection
There are a lot of reasons that can make a connection fail, even using keepalives and things like that; so you should think about a mechanism to restart it automatically.
What I would do is:
set up your SSH endpoint so that you can log in with a key in password-less mode: How can I set up password-less SSH login?
Prepare a script that do the connection in an infinite loop --- restarting if failing; use "keepalive" nonetheless;
launch it at boot: How do I get a program to start up at boot?
Notice that probably you will need to use su -c
(or sudo
) to run the ssh as your user --- commands in /etc/rc.local
are run as root. (Thanks @muru).
You say you want the connection to automatically restart if it is disconnected. There is a package to do that: autossh
. See, e.g. here for how to use it. That link also has a start-up script for making it restart on boot, though that's relatively trivial; it's the restarting on connection failure which is hard.