There’s a handy tool for Mac users that I rarely see getting use, the SSHFS filesystem. SSHFS is a FUSE filesystem uses the SSH File Transfer Protocol (SFTP) as it’s backend. The short of it is that you can mount a remote directory on your local machine with nothing more than SSH access.

FUSE is the Filesystem in Userspace, a operating system extension that allows non-root users to create mountable filesystems. FUSE is available for most UNIX-like operating systems, including OS X.

Installation

The first step to using SSHFS is to install FUSE for OS X (There’s a prior version called MacFUSE, you don’t want that). Once installed, reboot your Mac.

By itself, FUSE for OS X doesn’t do much, it provides the layer for userspace filesystems, but no filesystems itself, so download (found on the FfOSX page) and install SSHFS as well.

Mounting

Now that you have SSHFS installed, you can create a local SFTP backed volume with the sshfs command.

First you need a directory that you can mount the filesystem on:

1
mkdir ~/Desktop/mnt

Then run sshfs:

1
sshfs server.example.com:/var/www ~/Desktop/mnt -o defer_permissions -o volname=Server

The first option is the remote path, it can contain a username as well i.e. alice@server.example.com:/var/www. Because SSHFS uses SSH under the hood, your ~/.ssh/config settings are honored. Whatever ssh *something* does will apply to sshfs *something*:path. You can also leave of the path to the remote home directory i.e sshfs server.example.com: ...

When you are done, you can unmount the filesystem with:

1
umount ~/mnt

Or ejected it in the Finder.

Options

-o defer_permissions is important! The default behavior is use the normal system of checking UIDs for file access. Unless you have the same UID on both your Mac and the remote system, this is probably not going to work. defer_permissions let’s the remote system handle permission checks, if you can access a file on the server, you will be to access it locally. If you’re the kind of person who make sure that your UIDs are the same everywhere, then you need help, but you don’t need defer_permissions.

-o volname=Server sets the name that the volume will have in the Finder. Otherwise it’s called something like OSXFUSE Volume 0 (sshfs)

Mount Location

Where you mount it matters as that’s where the drive icon will appear. In the above example, I create the local mount point in the Desktop folder, which makes the drive appear on the Desktop when mounted. The downside of that, is then when the drive is not mounted, you have an empty folder that appear on the Desktop.

Another popular approach is to mount it in /Volumes, where OS X traditionally mounts drives.

1
2
mkdir /Volumes/server
sshfs server.example.com:/var/www /Volumes/server mnt -o defer_permissions -o volname=Server

The OS will automatically remove the directory when you unmount, you’ll need to create it each time, but you won’t need to clean it up.

Wherever you mount it, the drive icon will always appear in the Finder under Devices -> Your Computer. And, of course, if you’re using command line, the drive icon is pretty much a non-issue.

Sharing with Others

By default, the file system is only visible to the person that mounted it. To allow other users to see it you can add -o allow_other to the command line. This can be a little dangerous when combined with defer_permissions as everyone will have the permissions of the account that was used for the SSH connection. Use this option with care.

Workflow

As I’ve previously written, my perfered workflow for uploading to servers is to use a combination of Make/Rake and rsync. What I really like SSHFS for is browsing. Using the Finder I can open a folder and use the Quick Look feature to, say, search through a directory of images.

However, you can just as easily read and write files on the server through SSHFS, allowing you to apply your favor desktop tools to the remote files.

Additional Filesystem

There are wide variety of filesystems for FUSE, but unfortunately, most of them have not been ported to OS X. My favorite, conceptually anyway, I haven’t used it, is PNGDrive, a file system that automatically hides data in PNG files using Steganography

In terms of file systems that actually work under OS X, there’s a list here:

https://github.com/osxfuse/osxfuse/wiki/List-of-fuse-for-os-x-file-systems

The most useful are probably:

fuse-ext2 which allows you to mount ext2, ext3, and ext4 devices and images on your Mac and NTFS-3G for NTFS.

Comments