I have multiple raspberry pi's running Arch Linux (No GUI) in which I need to access. These pi's are behind firewalls in each unique location. Currently I use openvpn to connect to these but the costs of that system is expensive per license. I use the access server from them.
As a result, I am trying to design and setup a system that allows me the ability to login to my VPN server (vps) and run a command to search for a specific name (OfficeDevice1991) such as: customcommandsearch "OfficeDevice1991" and then it then returns the IP address of the machine or something I can use to SSH into with. I am also looking for the ability to run a command to list every active connected device. It lists back the IP, name and perhaps how long it's been active for.
For this goal, I of course need to create something that includes the name of the device (in this case OfficeDevice1991) and then that pi will be able to hook into my vps public server. From the public server, I can log in and do a search of every device connected to it and return information required to ssh into.
I have been looking into reverse SSH and so far I got one of my test pi's connected and accessible from my vps using the following commands:
PI:
ssh -fN -R 12345:localhost:22 -i /publickeyfile useraccount@ip //Pi's command to connect to vpn VPS:
ssh -p 12345 useraccount@localhost //command for vpn to connect to pi This works great, but using this method, if I was to implement it, I would run into a few issues:
- I would need to set up unique unused ports
- Some way to keep these ports / tunnels opened
- I need to come up with a system to identify each device. I can log each port to a name in like a text file locally? It would be beneficial to be able to include that in the ssh setup for each device if possible. I would still need to make sure the ports I use are not being used by any other programs or any device already there.
What I don't want to have to do
Check what ports are free to use for each RPI
Have to manually edit
.ssh/configto add a name to represent each port assigned to RPI from part 1 above.
I am writing this for information/assistance as to what to do for my goal.
Could anyone provide me with a suitable solution?
StreamLocalBindUnlink=yes. I followed and your solution now works a charm! I just need to make sure the connection stays live! Might use autossh for that. Need to test a few things of course as reading it states it overrides previous session or something? Thanks though! Will keep posting as i go along.