How to ssh into Mac on outside network when I can when on the same network
I can ssh just fine into my other Mac when both machines are on the same network using ssh -p 22 [email protected]
or ssh [email protected]
, but when I am on a different network, I cannot ssh successfully. I am met with "ssh: connect to host xxx.xxx.x.xx port 22: Network is unreachable". I have remote login turned on on the machine I am trying to get into. Any help is appreciated. Thanks!
Solution 1:
Different network services use different default "ports" to send information. Web pages use port 80, ssh uses port 22. Most likely your issue is caused by your router blocking port 22 access from outside networks.
To fix this you need to go to the port forwarding (not the firewall) configuration page for your router and add a rule which defines the relationship between your internal (home) network and the external (the Internet) network. Below is an example of port forwarding from my router.
The Name(User)
value does not matter, it is an internal reference only.
The important things are the:
-
LAN IP
, that will be the internal address of the computer you are trying to SSH to. -
External port
, this the port the router will open to let you connect ... it does not have to beport 22
. -
Internal port
, this is port on your computer ... it does not have to beport 22
, but if do not useport 22
though you will need change it to something else insshd.config
in/etc/ssh
or have software that does it for you (I am using Screens).
This page is from an ipTime router. Your router will probably be different, but the port forwarding page will have the same options. Once you have set up port forwarding, follow the instructions for saving configuration changes for your brand of router.
Before you close your router configuration webpage there is one more thing to do!
Find the WAN IP address
. It may or may not go by a different name on your router, but you will know this IP when you see it because it is the public IP address assigned to your router by your internet provider. You need this IP address to SSH to your computer from anywhere outside your home network.
So instead of using ssh [email protected]
you will use this: ssh username@Public-IP-address
.