I own a Macintosh laptop (10.11.2) that I would like to create a permanent reverse SSH tunnel.
This way, when I switch network, or the computer is stolen, I can remotely SSH into the device independent on what network it is on.
Currently, I run this command from when I am on the laptop, but if my network gets interrupted, I have to run it again.
ssh -N -R 2000:localhost:22 root@my_server_ip
(and then run ssh -p 2000 localhost
on my home server)
But if my laptop switches network, or I am not physically on it to run the command, the reverse SSH tunnel does not work.
Is there any mac command line solution for this?
Best Answer
There is
autossh
doing exactly what you need:But you should certainly reconsider running the tunnel using
root
account, when it is password-less (unless you have the key limited usingauthorized_commands
).