---
title: The joy of sshfs
date: 2013-02-10 08:00
slug: the-joy-of-sshfs
categories:
- Blog
tags:
- ssh
---

[remote pbcopy]: http://seancoates.com/blogs/remote-pbcopy
[homebrew]: http://mxcl.github.com/homebrew/
[fuse4x]: http://fuse4x.github.com/
[osxfuse]: http://osxfuse.github.com/
[sshfs]: http://fuse.sourceforge.net/sshfs.html
[expandrive]: http://www.expandrive.com/expandrive

![](https://brettterpstra.com/uploads/2013/02/tunnelfilesystem_01.jpg)

I know a lot of web developers still use FTP clients to work on remote servers. I prefer to have a local dev install and use scp, rsync and git to push changes whenever it's feasible. When I can't do that, though, I use [`sshfs`][sshfs].

`sshfs` (SSH Filesystem) allows me to mount a remote server over SSH on my local filesystem, very similar to the way [ExpanDrive][] does it (using FUSE). In addition to web design work, this can be great for system administration and other applications where you have to work on a remote server where you don't a full dev environment set up. You get to use your own tools on your local machine while working directly with the files on the remote, all with the security of SSH.

<!--more-->

If this sounds interesting, here's the easiest way to get started. Install [homebrew][] (if you haven't already), then use it to install `fuse4x` and `sshfs`:

	brew install fuse4x sshfs

> Side note:
> 
> You can grab a binary installer for [Fuse4X](http://sourceforge.net/projects/fuse/files/fuse-2.X/) and manually build [sshfs]([http://sourceforge.net/projects/fuse/files/sshfs-fuse/2.4/](https://github.com/fuse4x/sshfs)) if you don't want to deal with Homebrew, but for ease of install/uninstall, you really can't beat `brew`.
>
> There's also a new project called [Fuse for OS X][osxfuse] that is supplanting Fuse4X, but the above combination is perfectly stable for now and is --- to the best of my knowledge --- the path of least resistance for getting `sshfs` up and running quickly.
 
Make a folder called "mounts" in your home folder (or whatever/wherever you want to mount the filesystems, but you'll need to modify the following scripts). Add `rmount` and `rumount` below to your `~/.bash_profile` to be able to quickly mount and unmount remote directories locally:

```bash
# Remote Mount (sshfs)
# creates mount folder and mounts the remote filesystem
rmount() {
	local host folder mname
	host="${1%%:*}:"
	[[ ${1%:} == ${host%%:*} ]] && folder='' || folder=${1##*:}
	if [[ $2 ]]; then
		mname=$2
	else
		mname=${folder##*/}
		[[ "$mname" == "" ]] && mname=${host%%:*}
	fi
	if [[ $(grep -i "host ${host%%:*}" ~/.ssh/config) != '' ]]; then
		mkdir -p ~/mounts/$mname > /dev/null
		sshfs $host$folder ~/mounts/$mname -oauto_cache,reconnect,defer_permissions,negative_vncache,volname=$mname,noappledouble && echo "mounted ~/mounts/$mname"
	else
		echo "No entry found for ${host%%:*}"
		return 1
	fi
}

# Remote Umount, unmounts and deletes local folder (experimental, watch you step)
rumount() {
	if [[ $1 == "-a" ]]; then
		ls -1 ~/mounts/|while read dir
		do
			[[ $(mount | grep "mounts/$dir") ]] && umount ~/mounts/$dir
			[[ $(ls ~/mounts/$dir) ]] || rm -rf ~/mounts/$dir
		done
	else
		[[ $(mount | grep "mounts/$1") ]] && umount ~/mounts/$1
		[[ $(ls ~/mounts/$1) ]] || rm -rf ~/mounts/$1
	fi
}
```

These functions work with any host set up in `~/.ssh/config` (key pair access preferred, especially for scripting mounts). Say you have a section in your `~/.ssh/config`:

	host mm
	  HostName cookie.macminicolo.net
	  User monster

and you have a [key pair](http://www.paulkeck.com/ssh/) set up for password-less entry. Now you can just type `rmount mm` to mount the entire filesystem in `~/mounts/mm` (the script will auto-generate the folder name based on the host or directory name). Typing `rmount mm:/Users/monster` would mount only the Home folder of a co-located Mac mini in `~/mounts/monster`. Running `rumount monster` un-mounts the remote folder and removes the local mount point.

Why do this? Because, now you get all of the benefits of working on your own system. It's as secure as SSH/SFTP but with access to your local environment and applications, and there's no need to download each file you want to work on and wait for it to sync back up. Yes, it's a bit slower (a bit determined by bandwidth, of course) than your local filesystem, but the direct tunnel keeps things moving nicely[^sshtricks].

[^sshtricks]: There are a few things you can do to speed up any SSH connection, including turning on compression and setting up "master sessions." The post [9 Awesome SSH Tricks](http://www.tychoish.com/rhizome/9-awesome-ssh-tricks/) is a great place to start.

Some of the things I love about `sshfs` vs. SSH or an FTP client:

- `subl`/`mate` (no `rmate` or local listener required)
- `qlmanage -p` (Quick Look from the command line)
- quick file copy/move between filesystems (no `scp`, `rsync` or reverse tunneling needed)
- `pbcopy` and `pbpaste` (clipboard interchangeability)
- Finder access, because...
	- sometimes **I** trumps `ls -l`
	- previews are often _super_ handy
	- browsing a folder tree in Finder is faster than `ls, cd, ls, cd`...
	- Quick Look with [QLStephen](http://whomwah.github.com/qlstephen/), [QLColorCode](https://code.google.com/p/qlcolorcode/) and [MultiMarkdown QuickLook](http://multimarkdown.com/download/) is a beautiful thing.

There, did I sell you[^sell]?

By the way, [ExpanDrive](http://www.expandrive.com/ "ExpanDrive - SFTP/FTP/S3 Drive") for Mac just updated for the first time in quite a while. If you want all of this goodness in a GUI instead of the Terminal, check it out. Happy `sshfs`-ing.

[^sell]: Please note that I will not be compensated in any way if you start using `sshfs`. I don't think *anyone* will. I am not invested in your future, I just want the best for you. Because you're special. Stop it.

---

Brett is a writer and developer living in Minnesota, USA. You can follow him as ttscoff. This content is supported by readers like you. [More about Brett](https://brettterpstra.com/contact.md), including social links.

Copyright © 2026 Brett Terpstra. All rights reserved.
