-1

I used autossh in my raspberry pi to connect to one of my VPS.

But I have 4 raspberry-pi(s). I used the same script to connect to my remote VPS, so that I can login in every raspberry pi anytime remotely.

For those 4 pis, I used autossh in this way:

add this line to my /etc/rc.local on my 1st Pi.

sudo su pi -c "autossh -M 1122 -4 -NC -R \*:8822:localhost:22 [my_vps_username]@[my_vps_IP] -p 22" & So I can use

ssh -l pi [my_vps_IP] -p 8822 to connect to my 1st Pi.

If I want to connect to the 2nd Pi, I have to change the port to be 8823 or something.

sudo su pi -c "autossh -M 1122 -4 -NC -R \*:8823:localhost:22 [my_vps_username]@[my_vps_IP] -p 22" &

Here's the question:

How to have lots of SSH reversing connections without specifying port one by one?

I may have 100 Pi(s) and I need to connect to them via SSH anytime when powered on. To get rid of port duplicating, and manage those SSH connections systematically.

Appreciate!

dotslash
  • 219
  • 3
  • 15

1 Answers1

3

There is no magic here. Only a single application can bind to any one IP:Port tuple at a time. You are binding to 127.0.0.1:XXXX. To connect multiple tunnels, you will either need to maintain mapping tables of which ports they're binding to or which IP addresses they're binding to (Remember that all of 127/8 is available on your localhost interface).

There's no getting around this. You'll need to allocate ports and track them for each remote system.

EEAA
  • 108,414
  • 18
  • 172
  • 242