The following command will initiate a ssh tunnel and daemonize itself restarting the connection if it drops for any reason:

autossh -f -M 20000 -i /home/user/id_rsa -D 12345 [email protected] -N

More examples of using autossh to do this can be found here:)

Mario Loria is a builder of diverse infrastructure with modern workloads on both bare-metal and cloud platforms. He's traversed roles in system administration, network engineering, and DevOps. You can learn more about him here.