SSH to a Mac on the LAN with Bonjour
Apple macOS SSH networking zeroconfBonjour is Apple’s zeroconf technology. I wanted to SSH to another Macbook I have, but I want it to always work even if I’m on another network (provided we’re both on the same network). To do this, we just append the special “.local” TLD to the hostname of the target machine, and this tells the name resolution system to consult its MDNS database.
$ ssh andrew-macbook-air.local
The authenticity of host 'andrew-macbook-air.local (fe80::89:e537:200d:9e0d%en0)' can't be established.
ECDSA key fingerprint is SHA256:<redacted>.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'andrew-macbook-air.local,fe80::89:e537:200d:9e0d%en0' (ECDSA) to the list of known hosts.
andrew.imeson@andrew-macbook-air~ %
Pretty handy? If I don’t want to remember that, I can always throw it in my ~/.ssh/config file:
Host air
Hostname andrew-macbook-air.local
User andrew.imeson
Now it’s a simple ssh air
or scp bacon air:
away.
Another cool thing you can do is see which hosts on your network are broadcasting (well, multicasting, but on 99% of networks multicast gets treated like broadcast) for a given service:
dns-sd -B _ssh._tcp
Browsing for _ssh._tcp
DATE: ---Sat 05 Jun 2021---
15:57:33.094 ...STARTING...
Timestamp A/R Flags if Domain Service Type Instance Name
15:57:33.095 Add 3 4 local. _ssh._tcp. Andrew’s MacBook Pro
15:57:33.095 Add 3 5 local. _ssh._tcp. Andrew’s MacBook Pro
15:57:33.095 Add 3 1 local. _ssh._tcp. Andrew’s MacBook Pro
15:57:33.095 Add 3 13 local. _ssh._tcp. Andrew’s MacBook Pro
15:57:33.095 Add 2 13 local. _ssh._tcp. andrew-macbook-air
Reminder again that I’d like Zero Configuration Networking: The Definitive Guide for my birthday 😉