autossh: setup

Why? You want to access machine that is behind firewall or otherwise inaccessible. Even if connection has been down.

Example you want to make your home computer accessible from work. Home computer is not accessible, because it doesn’t have public IP.

Run ssh-keygen on home machine

Enter empty pass-phrase

Append contents of ~/.ssh/id_rsa.pub (home) to ~/.ssh/authorized_keys (work)

run (home)

autossh -M echo_port -R forward_port:localhost:22 work_host

where echo_port is random port (>1024) and forward_port that will forwarded to your home machine sshd port (22).

Now you can run from work machine

ssh localhost -p forward_port

If you are getting warning that remote host identification changed, then edit /etc/hosts file on work and add your home computer name to 127.0.0.1

eg

127.0.0.1 localhost home_computer_name

now you should able to connect from work computer to home computer by running

ssh home_computer_name -p forward_port

Leave a Reply