Vipul_Pinto
Posts: 4
Joined: Sat Sep 14, 2019 1:35 pm

How to auto ssh port forward on boot

Sat Sep 14, 2019 1:44 pm

I want to port forward on boot by command ssh -R port:ipaddress:port serveo.net
I want this command to be executed as soon as my raspberry pi (with raspbian lite) gets booted up.
I have tried by including command in /etc/rc.local but it didn't work... can some one help me with it.

pcmanbob
Posts: 9298
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: How to auto ssh port forward on boot

Sat Sep 14, 2019 2:10 pm

Hi.

What you look to be trying to do is SSH tunnelling , you will probably find that your networking is not up and running when the command gets called in /etc/rc.local, so you either need to set you pi to wait for networking in rasp-config or add a delay to your command in /etc/rc.local

some thing like this might work

Code: Select all

sleep 60 &&  ssh -R port:ipaddress:port serveo.net

that's always assuming that your command actually works from the command line.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Vipul_Pinto
Posts: 4
Joined: Sat Sep 14, 2019 1:35 pm

Re: How to auto ssh port forward on boot

Sat Sep 14, 2019 2:31 pm

pcmanbob wrote:
Sat Sep 14, 2019 2:10 pm
Hi.

What you look to be trying to do is SSH tunnelling , you will probably find that your networking is not up and running when the command gets called in /etc/rc.local, so you either need to set you pi to wait for networking in rasp-config or add a delay to your command in /etc/rc.local

some thing like this might work

Code: Select all

sleep 60 &&  ssh -R port:ipaddress:port serveo.net

that's always assuming that your command actually works from the command line.
The command is working in command line and I also tried with "sleep 60 && ....." but it is not executing on boot

tpyo kingg
Posts: 809
Joined: Mon Apr 09, 2018 5:26 pm
Location: N. Finland

Re: How to auto ssh port forward on boot

Sat Sep 14, 2019 3:04 pm

Are you using a key for authentication? If so you need to specify it within rc.local, too, using the -i option.

Andyroo

Re: How to auto ssh port forward on boot

Sat Sep 14, 2019 3:15 pm

Try piping the output from the command in rc.local to a file and see if that says anything...

User avatar
graysky
Posts: 98
Joined: Fri Apr 05, 2013 11:43 am
Location: /run/user/1000
Contact: Website

Re: How to auto ssh port forward on boot

Sat Sep 14, 2019 3:31 pm

You could write a script and have a systemd service execute it for you once the network is up rather than a sleep line... I assume your distro is using systemd.

Vipul_Pinto
Posts: 4
Joined: Sat Sep 14, 2019 1:35 pm

Re: How to auto ssh port forward on boot

Sat Sep 14, 2019 3:38 pm

tpyo kingg wrote:
Sat Sep 14, 2019 3:04 pm
Are you using a key for authentication? If so you need to specify it within rc.local, too, using the -i option.
Can you give an example for it

Vipul_Pinto
Posts: 4
Joined: Sat Sep 14, 2019 1:35 pm

Re: How to auto ssh port forward on boot

Sat Sep 14, 2019 3:48 pm

graysky wrote:
Sat Sep 14, 2019 3:31 pm
You could write a script and have a systemd service execute it for you once the network is up rather than a sleep line... I assume your distro is using systemd.
I am new at these can you tell me how to make it into a script

tpyo kingg
Posts: 809
Joined: Mon Apr 09, 2018 5:26 pm
Location: N. Finland

Re: How to auto ssh port forward on boot

Sat Sep 14, 2019 3:59 pm

Vipul_Pinto wrote:
Sat Sep 14, 2019 3:38 pm
Can you give an example for it
Please describe in more detail how you are connecting when you connect manually.

Have you made a key or not? When do you type in the passphrase for the key or the password for the connection?

User avatar
graysky
Posts: 98
Joined: Fri Apr 05, 2013 11:43 am
Location: /run/user/1000
Contact: Website

Re: How to auto ssh port forward on boot

Sat Sep 14, 2019 9:27 pm

Also, why are you doing this at all. I assume to circumvent the need to forward a port due to no access to the router in the building?

Return to “Beginners”