I learned about sshfs when using Daphile, the music server and player package for Intel PC’s. Daphile should connect to my Mac to access my iTunes library. I tried this before using SMB file sharing, but this failed due to sleep-wake cycles of the Mac. This made the SMB connection unreliable. Recent versions of Daphile support sshfs, and I hoped to avoid the issues I had with SMB. sshfs requires only a ssh account on the server and uses the sftp protocol to transfer data.

Unfortunately, my Mac went to sleep even during a sftp file transfer. With ssh, you can block sleep with setting “ttyskeepawake” using pmset. However, sftp sessions do not create a login and thus no tty. I tried all the network layer keepalive settings but none of them worked. Mac Os simply overrides them. Note that sftp (like ssh) uses the bonjour-proxy function to keep the session open. So during a file transfer, when the Mac goes to sleep, it transfers the session to the bonjour proxy (my Apple TV). The proxy then notices the traffic and wakes the Mac using WOL. After a few minutes, this cycle repeats itself. Very cool, but not what I wanted.

The solution that solved all my problems and made the sshfs sharing rock-solid involved caffeinate. This is the (now official Apple) tool to keep the Mac awake. sftp sessions are handled by the sshd server that starts the “sftp-server” program with each sftp session. Just replace “/usr/libexec/sftp-server” with “/usr/bin/caffeinate -s /usr/libexec/sftp-server” in “/etc/ssh/sshd_config” and you’re done.

# override default of no subsystems
Subsystem sftp /usr/bin/caffeinate -s /usr/libexec/sftp-server

Later I refined my Daphile setup by syncing my iTunes library to the Daphile server using the backup/restore function of Daphile. This uses sshfs again, but now only during the backup/restore. I use the backup/restore function to sync from the iTunes sshfs share to the local disk. The backup/restore function is based on the unix rsync program, is extremely fast, and supports incremental backups. The full sync took nearly two hours for 200 GB iTunes music (syncing to an USB2 external disk..). The next incremental sync took less than 2 minutes for scanning my iTunes Library for updated or new music files. Make sure to copy the iTunes Library.xml file as well, or you loose your playlists. With this setup, I could manage my iTunes library on a MacBook that I carry with me, and still be able to independently play music at home… nice.

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 28 = 30