Mounting Filesystems in Mac OS X via SSH
January 8, 2012Background
Over the past month or so, I've been learning to be more and more efficient with the Vim editor. As anyone that's used Vim knows, your vimrc configuration file quickly becomes your best friend. Rather than duplicate and sync the file across all of systems that I work on daily, I've found it easier to mount the remote systems as if they were local volumes and just edit files using my perfectly customized local Vim setup.
Previously I was using Transmit's "Mount as Disk" feature to access remote machines, but it turns out that it has very aggressive caching that often fails to recognize changes to files made outside of the local machine. This caused me not to see code edits made by a coworker and subsequently let me overwrite them with no notification.
Instead, I found two very cool pieces of software that allow you to manually control caching - Fuse4X and SSHFS. Check out the steps below to see how I set them up.
Requirements
- A Mac, obviously. ;) As of the writing of this post, I'm running 10.7.2.
- Install Homebrew if you haven't already.
- Install xCode, as you'll need it to compile SSHFS and Fuse4X.
- If you've previously used MacFUSE, be sure to completely uninstall it.
Step 1 - Install git
You may already have this installed, but in case you don't, type this into the terminal:
brew install git
Step 2 - Install Fuse4X and SSHFS
brew install fuse4x sshfs
Step 3 - Link Fuse4X as root
sudo brew link fuse4x
That's it, you're done!
Mounting a filesystem
To mount a filesystem, use this command:
sshfs user@host:/dir /tmp/ssh -ocache=no -onolocalcaches
The "-onolocalcaches" option prevents aggressive caching and grabs the freshest copy of a file when it's opened.
Full details of SSHFS and its command arguments can be found in its manual pages.
For the sake of automation, I also have a bash script set up to auto-mount my drives. This saves a lot of time for when I have 10 different servers I need to work on.
