Thursday, 26 February 2009

Automatic mounting of SSH filesystems in OS X

Getting your MacFUSE SSH filesystem to mount automatically on login isn't Voodoo, but it is Magick.

Here's how it's done using launchd:

Create a Properties List file under, ~/Library/LaunchAgents:

eg: ~/Library/LaunchAgents/com.example.sshfs.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>com.example.sshfs</string>
    <key>ProgramArguments</key>
    <array>
      <string>/opt/local/bin/sshfs</string>
      <string>user@example.com:path/to/share</string>
      <string>/path/to/mountpoint</string>
      <string>-f</string>
      <string>-o</string>
      <string>auto_cache,reconnect,volname=friendly_name</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
  </dict>
</plist>

We can now load this into launchd by running,
$ cd ~/Library/LaunchAgents 
$ launchctl load com.example.sshfs.plist

Your SSH filesystem should now be mounted.
$ mount
    .
    .
    .
user@example.com:path/to/share on /path/to/mountpoint (fusefs, nodev, nosuid, synchronous, mounted by user)