OSX – How to Use /etc/fstab and Automount with SSHFS

automountmacosmountsshfs

I'm attempting to automount a directory from a remote Ubuntu machine on my Mavericks Mac. SSHFS works perfectly when mounted manually, in many different ways. The standard sshfs mount works great:

sshfs user@desk:/home/user desk 

and I can even use mount:

sudo mount -t sshfs -o allow_other,IdentityFile=/Users/user/.ssh/nopass_id_dsa user@192.168.1.2:/home/user desk

(I followed the OSXFuse automounting instructions to set up mount_sshfs)

I want to turn this into an automount. The easiest, recommended by OSXFuse way is to turn the above mount command into an /etc/fstab entry:

user@192.168.1.2:/home/user    /Network/desk   sshfs   allow_other,IdentityFile=/Users/user/.ssh/nopass_id_dsa 0 0 

but that doesn't work:

Network $ sudo mount desk
mount: desk: unknown special file or file system.

Similarly, if I do sudo automount -vc then I either get a long timeout or an unhelpful "Operation not permitted" error when I try to enter the mount point, depending on how I play with the formatting of fstab options. I get the same errors when I try to set up an automount map, as described here.

What's wrong with my fstab entry? Or, how else can I automount sshfs on OSX?

(I'm on 10.9.5 with sshfs 2.5.0 from homebrew)

Best Answer

Due to a bug in OSXFuse, this is necessary for the allow_other flag to work:

sudo sysctl -w osxfuse.tunables.allow_other=1

This may or may not fix the fstab issue, but it does work with a direct map. Here's how I set mine up.

Add this line to /etc/auto_master:

/-                              auto_ssh          -nobrowse,nosuid

create /etc/auto_ssh:

/Users/USER/MOUNT_POINT          -fstype=sshfs,allow_other,idmap=user,cache=no          USER@LINUXMACHINE:/home/USER

(assuming you have passwordless keys set up.)

Tell autofs about your changes:

sudo automount -vc

To make the osxfuse.tunables.allow_other change survive a reboot:

Put the following in /Library/LaunchDaemons/sysctl.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>Label</key>
 <string>sysctl</string>
 <key>ProgramArguments</key>
 <array>
   <string>/bin/bash</string>
   <string>-c</string>
   <string>/Library/Filesystems/osxfusefs.fs/Support/load_osxfusefs; /usr/sbin/sysctl -w osxfuse.tunables.allow_other=1</string>
 </array>
 <key>RunAtLoad</key>
 <true/>
</dict>
</plist>

Load the plist with:

launchctl load /Library/LaunchDaemons/sysctl.plist
Related Question