SSH to Your Mac From (Almost) Anywhere

13 Feb 2013

Some time last year I was sitting at a coffee shop hackin’ away on my work laptop. I noticed that my other laptop, which was sitting at home, was showing up in the Finder sidebar. I assumed it was just cached from when I was at home, but when I clicked on it I was amazed to discover that after a brief delay I was connected to my Mac at home.

It occurred to me that this was probably Back to My Mac at work, and I got curious about how BtMM works. In the process of investigating, I learned enabling BtMM on a Mac causes that machine to be advertised via mDNS on any other Mac that is attached to your iCloud account and has BtMM enabled. What’s more, you can SSH to that host and be connected to your Mac. It’s trivial to enable this and pretty easy to use.

Prerequisites

There are a few things you’ll need first. You’ll need two Macs running Lion or
newer. You’ll need an iCloud account. You don’t need a router that supports
UPnP, but you’ll be much happier if you have one.

Update: Thanks to Eric Hodel who pointed out that
it’s not actually a public DNS entry, rather it’s published via mDNS on hosts
that have BtMM enabled. This means that you can only access your remote Mac from
another Mac, but that’s okay.

Enabling Back to My Mac and SSH

Crack open System Preferences and open the iCloud prefpane. Ensure that Back to
My Mac is checked: