Ssh – Monitoring an SSH tunnel

sshssh-tunnel

I have a requirement to have a users home workstation (mac) connect via ssh tunnel to a corporate bastion host (bastion.corpnetexternal.com) and through to a mac workstation (host.corpnetinternal.com) in the corporate network. Here is the connection string:

ssh -N -f -L 2345:host.corpnetinternal.com:22 user@bastion.corpnetexternal.com

This is known to work, so no worries there.

The ssh tunnel needs to be automatically created and there must be monitoring ensure that it is functional end to end, and if not to be restarted.

Additionally, this functionality may not be dependent on or interrupted by a VPN tunnel that may or may not be present from the user remote workstation into the corporate network.

I would appreciate any suggestions. Please, no comments on the why of using ssh tunneling if a VPN is available. I have listed the requirements levied upon me.

Best Answer

AutoSSH does exactly what you need.

On MacOS, it can be installed through Homebrew with brew install autossh.

See the README for usage instructions, or here and here for some examples.