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?

1 Answer 1


There is autossh doing exactly what you need:

autossh -M 12345 -N -R 2000:localhost:22 root@my_server_ip

But you should certainly reconsider running the tunnel using root account, when it is password-less (unless you have the key limited using authorized_commands).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .