Creating SSH tunnel without running the ssh command

267 views Asked by At

Establishing SSH tunnel can done from the command line by explicitly giving

ssh -N -f -L 18888:192.168.224.143:8888 [email protected]

or defining tunnel in ~/.ssh/config file

Host tunnel
    HostName 192.168.224.143
    IdentityFile ~/.ssh/mine.key
    LocalForward 18888 192.168.224.143:8888
    User username

and then running,

ssh -f -N tunnel

Is there a way to start this tunnel without running the ssh ssh -f -N tunnel command explicitly?

I would like to establish this tunnel whenever my machine boots up. Do not want to add it in init script. Can it be done with SSH configuration itself?

1

There are 1 answers

0
Jakuje On BEST ANSWER

No. SSH configuration is not designed to start something for you automatically. You need to add it to your startup applications or init script/systemd service, if you want to start it automatically after the network.

I also recommend you to use autossh which will take care of re-establishing the tunnel, if it fails for some reason.