FUSE and SSHFS: Mount your Server as a Local Volume on OS X

Image under CC licence: see https://www.flickr.com/photos/ferg2k/3614417730

Since my Vim skills had sharpened over the past five years, I hadn't really looked into using FUSE/SSHFS to mount my remote server as a local volume, since my primary usage of it had been to quickly edit config files and scripts on remote hosts.

It was only recently that I realised how great that it would be to be able to use it once again in order to simplify how I create and test some of the interactive elements of this site (the embedded D3 bits, for example).

Let's take a look at FUSE, SSHFS, and how we can use them.


FUSE (and its library libfuse) essentially allows for user-space filesystems to be mounted and unmounted in Unix-y systems such as Linux and OS X. The nice thing about this is that almost any type of service that can store data can be abstracted to 'mimic' the mechanics of a filesystem, using libfuse under the hood to perform the mapping between the two. For example, GMailfs presents your GMail account to the OS as a filesystem by storing chunked data in attachments. Genius!

One of the more practical implementations however is SSHFS, which abstracts SSH's file transfer protocol SFTP. You might already be familiar with it from those awkward website deployment scripts that you inevitably end up writing at the end of a project.

It's worth looking into the sftp tool if you haven't already. You can use it interactively by just saying sftp username@remote_server and then using the get and put commands to download and upload things, or you can use it to quickly get/ put something from your remote server in one command. Digitalocean actually have a pretty good tutorial on it.

On OS X at least, installation of both FUSE and SSHFS is straightforward from the links at the bottom of this post. Once installed, you should have ssfhs in your $PATH.

Mounting and Unmounting a Remote Host (OS X)

Let's mount a remote server on OS X! Get a terminal window open.

Our target is to link a local 'mount point' directory to a directory on the remote server.
Our target is to link a local 'mount point' directory to a directory on the remote server.
First, we need to create a mount point directory on the local machine. Personally, I mount everything in /Volumes to keep things organised. It's just a directory, so create it using mkdir, giving it a descriptive name such as the name of the server:

Once the mount point is created, we can link the remote server to this newly-created mount point using SSHFS:

Note: Depending on your setup, you may be asked for your password. If you are, consider using SSH keys for passwordless entry in future.

Screen Shot 2016-09-01 at 09.50.45If you did choose /Volumes to mount in, then Finder should show you something like this in the sidebar. You can now start browsing <your_username>'s home directory as if it were a local one.

If you don't see the shortcut, hit shift+cmd+g in Finder to go directly to a specified path or browse to it on the terminal.

Browsing a remote host in Finder using SSHFS.
Browsing a remote host in Finder using SSHFS.
Neat, isn't it? Be aware that the reliability of this approach does depend upon your connectivity, and some things are obviously best done directly on the host via SSH.

Also, be aware of the security implications: if someone can access your local machine whilst you're mounted, then they can access your remote machine too.

When you're done, unmount using OS X's umount command:

You may get a message about the volume being in use. Be sure to quit anything that might be using the volume. If you still get the same message and you're absolutely sure it's safe, then you can pass the -f flag to umount to force an unmount. Just don't make a habit of that.

Final word: Following Symlinks

If you have symlinks on your server, you'll be slightly confused when you attempt to follow one. By default, the symlink is transferred directly to your local machine and interpreted there, which means that it'll try to follow to the target path on your local machine.

This is almost certainly what you do not want. To translate symlinks on the server end, just add -o follow_symlinks to the end of your SSHFS command.

Where to Obtain FUSE & SSHFS

Both FUSE and sshfs are available for OSX from the FUSE for OS X site or more generally from the libfuse Github.

Cat in Filing cabinet image under CC licence: see https://www.flickr.com/photos/ferg2k/3614417730

Leave a Reply