I have 2 computers on linux (ubuntu like), both are on separated local networks (192.168.xxx.xxx).
I would like to connect through ssh to Linux2 from Linux1 but it doesn’t have any public IP.
I have also a public server (srv.domain.com) I suppose that both PC could connect to server and it would be able to forward commands ??
But I can’t figure out how to do that. Is someone already did something similar and can explain it to me.
I have root access on all machines
Thanks a lot for your help !!!
Advertisement
Answer
The easiest way would be to make the firewall/router allow ssh connections between the hosts. But there is another way:
If your server can reach both clients, you can ssh onto the server and redirect a port to the ssh on the other machine:
ssh -L 1234:CLIENT2:22 -l USERNAME SERVERNAME
after logging into the the machine open another terminal window and enter:
ssh -l USERNAME -p 1234 localhost
- USERNAME should be replaced with the username on the server/second client.
- CLIENT2 should be replaced by the ip or hostname of the second client.
- SERVERNAME should be replaces by the name of your server.
You can also ssh onto the server and open another ssh session from there. But that would be to easy 😉
If your server cannot reach the clients you have to build the tunnel the other way round:
ssh -R 1234:22 -l USERNAME SERVERNAME
after logging into the the machine open a terminal window on the other machine and enter:
ssh -l USERNAME -p 1234 SERVERNAME
- USERNAME should be replaced with the username on the server/second client.
- SERVERNAME should be replaces by the name of your server.