How to set up a host so that you can connect to it via ssh from a host that is located on another local network.
And how to connect via ssh to a host that is located on another local network.
Both hosts are connected to the Internet.
ssh username@public_ip_adress does not work.

  • The question is not clear. ssh ip_address than not happy? - Smithson
  • @Smithson Something does not work. - jisecayeyo

2 answers 2

forward ports from one network to another: google: // nat, routing.

How specifically to forward ports - depends on the router / OS (if routing goes through the software router, not through the interface) Port forwarding is necessary so that the router that receives network traffic knows that the connection to port 22 needs to be sent to one of the specific computers in the current local network.

if the networks are remote, i.e. not connected by routers within, conditionally, of the same building:

if there is access to the Internet from both networks, but both sides do not have a white ip (available from outside the provider's network) - buy vpn access / put openvpn on your hosting and connect to virtual network addresses.

on one of the computers / routers in both networks you will have a vpn-client installed, it will distribute traffic from the virtual network to the other computers (if access is needed by more than one computer)

google it like this: "connect networks via internet vpn" (even better in English, there are better instructions) - since the details also depend on the OS / connection schemes (the presence of a white ip), etc.

  • What is port forwarding for? And should the connection to the local host via the public ip-address work? - jisecayeyo
  • one
    through the public ip address it will work if the computer is directly connected to the wire from the provider - if not connected, you must forward the port from the router (in its settings) to one of the computers (google: // nat name of the router) and yes, make sure that the firewall allows access through these ports. And yes, I recommend changing the ports of ssh-servers from 22 (and on the router too) to something else, so the probability of hacking is slightly less - strangeqargo

If your host is only in the local network, then you can connect to it only from this local network.

  • Internet access from both hosts too. - jisecayeyo