7

I'm currently trying to get Apple's automount working with osxfuse and sshfs. The result should be that a specified folder gets automatically mounted if it is used.

What I've done so far:

  • installed osxfuse and sshfs from the official packages (versions are osxfuse: 2.7.3 / sshfs 2.5.0)
  • created a symlink /sbin/mount_sshfs -> /usr/local/bin/sshfs
  • appended the following config line to /etc/auto_master : /- auto_ssh -nosuid
  • created the /etc/auto_ssh config file:

    /mnt -fstype=sshfs,sshfs_debug,allow_other,idmap=user,follow_symlinks,max_read=65536,rw,nodev,cache=no,IdentityFile=/Users/myUsername/.ssh/sshfs remoteUser@remoteHost:/path/to/folder
    
  • afterwards reload automount via : sudo automount -cv

If I now try to cd into mnt i get the following error:

bash: cd: /mnt: Operation not permitted

The console contains the following:

04/12/14 01:27:50,418 automountd[1965]: MOUNT  REQUEST: name=/mnt [] map=auto_ssh opts=nosuid path=/mnt direct=1
04/12/14 01:27:50,631 KernelEventAgent[69]: tid 54485244 received event(s) VQ_DEAD (32)
04/12/14 01:27:50,632 automountd[1965]: MOUNT  REPLY  : status=1, AUTOFS_DONE
04/12/14 01:27:50,632 automountd[1965]: mount of /mnt failed: Operation not permitted

Does anyone have any idea how to make this work, or what to try next?

2

FWIW, if anyone else stumbles across this old question, the best guide I have found for mounting sshfs using apple's automounter is here -

http://virtuallyhyper.com/2013/07/mount-various-file-system-with-autofs-on-mac-os-x-mountain-lion/#mount-sshfs-with-autofs

2

Update 2016-08-03: I found that installing SSHFS from https://osxfuse.github.io is stabler than the homebrew version, because of some old dependency (therefore this may improve in the future).

CAVEAT: This connection is super fast when it works, but often has issues after terminated connects due e.g. wireless, standby.


Assumes you have Homebrew installed (make your life easier and get this first)

Installation of SSHFS

brew install sshfs

Check this folder to see installed file systems: ls /Library/Filesystems If you don't see osxfusefs.fs, you need to install it.

Get Cask

brew tap caskroom/cask

Install OSXFUSE

brew cask install osxfuse

Alternatively instead of homebrew use the download versions from https://osxfuse.github.io/

SSHFS + OSXFUSE Now Installed. One more step...

autofs needs mount_* binaries.

/usr/local/bin/sshfs should be also available as mount_sshfs, so:

List your mount_*s with

compgen -c | grep ^mount

OR

ls /sbin | grep mount 

If you do not see mount_sshfs, the you need to do this step. This is a critical step because it is easily forgotten and may create headaches.

sudo ln -s $(which sshfs) /sbin/mount_sshfs

Add Autostart at Boot Daemon in /Library/LaunchDaemons/

File could be called:

You need to run this at every boot for the kernel extension:

/bin/bash -c "/Library/Filesystems/osxfusefs.fs/Support/load_osxfusefs; /usr/sbin/sysctl -w osxfuse.tunables.allow_other=1"

So create a new service file:

/Library/LaunchDaemons/load.osxfusefs.tunables.plist

Contents:

<?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>Disabled</key>
    <false/>
    <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 with launchctl (launchd) for next boot, which is the Mac OS X version of systemctl (systemd)

launchctl load /Library/LaunchDaemon/load.osxfusefs.tunables.plist

Setup auto_master and auto_sshfs

The following assumes you can ssh into your server with a secure key (no password required).

/etc/auto_master

/mnt/sshfs                auto_sshfs       -nosuid

/etc/auto_sshfs

You could use parameters that normally come after the -o in sshfs -o depending on your situation.

  • idmap=user: default setting. since your uid and gid is probably different across operating systems, you could just map the user used in the user@ip: to your local (client) user. The group will be ignored in this case (which means folders not owned by you yet grant you read permissions on the server-side group may not be readable locally--on the client side)

OR

  • uid=YOURUSERID, gid=YOURGROUPID: just type id YOURUSER to get the numbers. This will just map all files from the mount to this user/group combination. This will allow you to read all files. I think any new files/folders you create will inherit the default umask settings for whichever folder you mount.

  • allow-other: I use this, but is is risky because any user who browses the mount will view the mount using the credentials used when connecting.

  • list all parameters with man sshfs and read see each parameter after every -o

replace:

  • YOURUSER with your username and
  • PRIVATEKEY to your key e.g. id_ed25519
  • ip with your ip address or hostname

Contents Important is the parameter reconnect, otherwise whenever you loose connection (like go to sleep), Finder will crash.

Replace

  • $(id -u) with your actual id on client machine
  • $(id -g) with your actual group id on client machine

Unfortunately you cannot execute things in autofs like id -u

NameOfMountThatGetsIgnored -fstype=sshfs,port=22,reconnect,uid=$(id -u),gid=$(id -g),follow_symlinks,allow_other,IdentityFile=/Users/YOURUSER/.ssh/PRIVATEKEY,volname="NameOfMount"     YOURUSER@ip:/path/on/server

Test

df -Ph /path/to/mount

List mounted filesystems

lsvfs

List all mounts

mount
  • 1
    I've been trying to get this to work, but it seems like some recent changes in macOS make it more difficult than it should be. It is not possible to symlink sshfs into /usr/sbin/mount_sshfs. Possibly an issue with SIP? You don't happen to know a workaround, do you? (would rather not turn off SIP to make the modification, but I will if I have to; any way to get /usr/local/sbin/mount_sshfs to work?) – Morgan Rodgers Oct 5 '18 at 7:01
2

For macOS Mojave and latest version of osxfuse, this is the correct daemon file:

<?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>Disabled</key>
    <false/>
    <key>Label</key>
    <string>sysctl</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</string>
        <string>-c</string>
        <string>/Library/Filesystems/osxfuse.fs/Contents/Resources/load_osxfuse; /usr/sbin/sysctl -w vfs.generic.osxfuse.tunables.allow_other=1</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

load_osxfuse is now located at /Library/Filesystems/osxfuse.fs/Contents/Resources/load_osxfuse and the correct kernel parameter is vfs.generic.osxfuse.tunables.allow_other

More info at osxfuse wiki

1

This doesn't require disabling System Integrity Protection, as cron jobs are still working in el captain:

$ crontab -e

*/5 * * * *  /usr/local/bin/sshfs 192.168.1.2:/etc /Users/xxx/temp/etc -o uid=$(id -u) -o gid=$(id -g) -o reconnect
  • Is your answer to disable System Integrity Protection or is this a new question? – abc Oct 25 '18 at 16:52
  • This is just another way to achieve an automount behavior. This Works without disabling sip.. – Benni Oct 26 '18 at 22:48
  • Ok, just clarifying. I've edited your answer to make it more clear. – abc Oct 26 '18 at 23:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .