I need to access some servers inside NAT. Since I do have a public server, this is what I am doing:
Both A and B have a service that runs the command: ssh -fnN -R 17000:localhost:22 [email protected] -i privateA
Only difference is the port. For B it is 17001.
This creates a sleeping connection from servers inside NAT to my public server 24/7.
Now I can connect any time to S and use the command: ssh -i privateS -p 17000 user@localhost
to connect to A.
Great. It solves my immediate problem. But while checking for ways to do it I had other option and I was not able to find a way to actually use it.
Main drawback of this method is to be sure to know every server remote port in advance and configure each server to use it since port selection came from command in A and B not in S.
If we use -R 0:localhost:22
on first commands (in both A and B), it all works the same, but the remote port will be random. And the SSH command even echoes back the number of the port created in S. But this information is available in A and B only.
From S I simple see two open ports in listen mode but do not know the one to use to reach A or B.
Imagine instead of 2 I have 50 remote servers.
How can I identify every SSH connection?
My first attempt was to use commands inside my authorized_keys file and do identification by the private file in use. Here I could retrieve the SSH process and then a list of ports under that process.
But, since I am using -N
commands aren't executed at all. What other method I could try?
What is the usage of a command that creates random port on a remote machine and do not share this information to it? What is the intended usage of -R 0:host:22
?
Again, my problem is solved, just trying to learn here...