SSH into iMac from public internet

0

I have tried to setup Remote Login in Sharing on my iMac with Mojave. However, the IP given is 192.168.x.x on the local network. If I look up the Macs public ipv4 or ipv6 address and try to SSH to it, it doesn't connect and only connects with the local IP. How can I connect through the public internet?

Steve M

Posted 2019-05-30T13:41:10.723

Reputation: 256

Answers

2

The problem is, most likely, the router you use to connect to your ISP.

Most ISP's provide a router to the end user but some allow you to use your own.

What is happening here is that the router has the public IP address and uses NAT to let the computers on the other side of the router to access the internet without a publicly accessible, unique IP address.

If you try and SSH into the public IP address of that Mac you are actually trying to SSH into the router rather than that Mac.

What you have to do (in general terms, because every router does this a little differently) is enable IP Address Forwarding. What this does is forward any connection attempts on a particular IP port to a specific IP address inside the local network.

SSH has a standard port it uses (port 22) but forwarding the typical SSH port number on your router to that Mac could open the Mac to hacking attempts. I would set it up to use a random higher number port to make it less obvious (security through obscurity, which is, ahem, better than nothing)

Once you have set up your router to forward requests on a specific port to a specific Mac, all you have to do is set up SSH on both computers and it should connect.

I would recommend setting up a private authentication key on both ends to secure your session and make it much more difficult for the Mac to be hacked. The additional benefit is no username and password to remember.

Steve Chambers

Posted 2019-05-30T13:41:10.723

Reputation: 274