How to ssh into a remote computer

I have two laptops, one running Ubuntu (server) and another running Debian (client), and I want to use ssh to log in to the shh server. While on my router's network, using the private IP address of the server works fine. However, as soon as I leave the network (client), such as connecting to my phone's hotspot or using some other network with internet access, I can no longer connect, using either the public or private IP. The service being used to connect is openssh.


By design, if you have a LAN behind a NAT router, it is not possible to connect from outside to inside your LAN. Private addresses have no meaning outside your LAN (that's why they are called "private") and using the public address, you will connect to your router only and not to any machine inside your LAN. As @user535733 has pointed out, you need to set up port forwarding on your router so that the router knows that connections to a particular port (say, ssh port) on the router should be forwarded to a particular machine inside your LAN. This has nothing to do with Ubuntu or Debian itself and you have to check your router's documentation on how to do that.