Trying to SSH tunnel on startup

Hello everyone,

I'm trying to do SSH tunnel that go up on startup.
i wrote initscript:

#!/bin/sh /etc/rc.common

START=99
boot() {
while true
do
ssh -fN -R 0.0.0.0:80:127.0.0.1:80 root@server -i /root/identityFile
sleep 10
done
}

The ssh command alone is running well but the initscript isn't running.

I would appreciate your assistance
Joe

It would be simpler to add that to rc.local.
Did you make it executable?
Did you enable it?

As you suggested, I changed it to rc.local.
and for both of your questions. yes its executable and enabled.

Still not working.

I suppose you added the ssh command only in the rc.local file, right?

like this:

# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.


ssh -fN -R 0.0.0.0:80:127.0.0.1:80 root@server -i /root/identityFile

exit 0

While ago i tried to put while loop and my router stocked in boot loop :sweat_smile:

It won't work as it is ( lack of shell or something like that)
A couple of solutions:
https://github.com/warybyte/ssh-callback (be careful with the paths, not exactly the same with OpenWrt)
https://www.everythingcli.org/ssh-tunnelling-for-fun-and-profit-autossh/ (exists in opkg, should be the best to use).

Thank you.
It's works well.
Thank you very much

Which one did you use? Could you post the command line you used as well?

1 Like

I used this guide:

If any one will ever want toy do autossh, this guide is more relative to Openwrt and pay attention to the known bug in the guide:
https://openwrt.org/docs/guide-user/services/ssh/autossh

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.