SSH to MacOS X (El Capitan) through iCloud tunnel

After my wedding and a honey moon in Sicilia, I am back home to blog about some cool tech stuff. Yesterday, I update my favorite laptop it’s a MacbookPro [ja keyboard] (Retina, 13-inch, Mid 2014) with the new MacOS X 10.11 El Capitan version. I also like MacOS software because it includes bash, ssh and lot of cool Linux/Unix commands. I have got also an MacMini at home behind my Internet box. For some time, I was looking for some out of the box stuff to connect to my MacMini with SSH via iCloud stack. Finally, I google it and I found some good infos/news about this issue.

How to setup a SSH connection via iCloud tunnel with 2 Macs

Let’s see how to do it.

Requisites

  • Have two mac
    • laptop one (MacbookPro) directly connected to Internet
    • server one (MacMini) behind an Internet box
  • Have an iCloud account

Back to my Mac setup (MacMini)

Check the correct option into your iCloud account inside the MacMini server configuration panel.

You should show now you MacMini server available into your Finder’s left panel.

More information to the official Apple help center

Locate MacMini server

First of all, we need to retrieve connection information to use ssh protocol. We gonna use some commands line to find your MacMini trough the iCloud.

First step

we need to find our iCloud account and our iCloud FQN DNS name

[mbp:~]$> dns-sd -E

Looking for recommended registration domains:
DATE: ---Fri 02 Oct 2015---
20:29:07.366  ...STARTING...
Timestamp     Recommended Registration domain
20:29:07.367  Added     (More)               local
20:29:07.367  Added                          icloud.com
                                             - > btmm
                                             - - > members
                                             - - - > 1122334455

My iCloud FQN DNS name is 1122334455.members.btmm.icloud.com

Second step

After finding our iCloud DNS name, we gonna retrieve our MacMini server with ZeroConf/Boujour Protocol. To find it we will use an other command line. This command collects all machine plugged with your iCloud account and sharing _ssh service.

[mbp:~]$> dns-sd -B _ssh 1122334455.members.btmm.icloud.com

Browsing for _ssh._tcp.1122334455.members.btmm.icloud.com
DATE: ---Fri 02 Oct 2015---
20:34:10.344  ...STARTING...
Timestamp     A/R    Flags  if Domain               Service Type         Instance Name
20:34:10.345  Add        3   0 1122334455.members.btmm.icloud.com. _ssh._tcp.           MacMini
20:34:10.345  Add        2   0 1122334455.members.btmm.icloud.com. _ssh._tcp.           MacBookPro

Last but not least step

We find our iCloud FQN DNS and our MacMini name. Now we can connect to it through the iCloud tunnel. If your server name contains some “ “/space character, replace it with “-“/dash one (sed -e “s/[[:space:]]/-/g”).

[mbp:~]$> ssh MacMini.1122334455.members.btmm.icloud.com
Last login: Fri Oct  2 21:18:27 2015 from xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
[mac-mini:~]$>

Conclusion

Connection through the iCloud service is quite easy. Unfortunately, there are few documentations for geek and tech user but with the Unix/Linux commands you can retrieve lot of familiar stuff you like. Now it is a really new service I’ve built and I don’t have a huge feedback, but let’s use it !!!

Last tip (c’est cadeau)

To facilitate your ssh connection, you can use ssh config file (.ssh/config) to logon to your MacMini server. Just edit it with your personal text editor (atom for example).

Host MacMini_iCloud
  HostName MacMini.1122334455.members.btmm.icloud.com
  User XXXXX
  ServerAliveInterval 10
  ServerAliveCountMax 6

and logon with :

[mbp:~]$> ssh MacMini_iCloud
Last login: Fri Oct  2 21:25:00 2015 from xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
[mac-mini:~]$>

Tag

Date