Using SSHFS to make files locally accessible

Introduction

One of the nuisances of CS 105 is the fact that the programs have to run on Wilkes; that means that your files have to be accessible there. That's not a problem if you're working on Knuth of one of the lab Macs, because those computers share all files with Wilkes. But what if you're working on your laptop? One approach is to edit locally and then use scp or putty to copy files back and forth. But that's clumsy. A second is to learn to use an editor like emacs or vim, which are capable of operating inside a remote terminal window. That's an excellent option, and I recommend it. But some people have a different preferred editor that requires a local GUI.

So wouldn't it be nice if your files were automatically shared with Wilkes? It turns out that you can achieve that result with sshfs, which is available for Linux, Mac, and (sort of) Windows.

The Basic Idea

In essence, sshfs works as follows: you tell it the name of an empty directory (folder) on your local computer, and a populated directory tree on a remote machine. The program will then make the remote tree magically appear to be present in your local folder. For example, suppose you have a folder named ~/courses on Knuth (or equivalently, Wilkes). You can create a local directory named knuthstuff and pass its name to sshfs. (This is called "mounting" the remote filesystem.) Now all of your existing files from ~/courses will magically appear in knuthstuff! You can read them, write them, and edit them to your heart's content. Then you can switch to a Wilkes window to compile and run the program. Pretty nifty!

Setup

Linux and Mac OS X

To get started, you need to install the sshfs software. On Linux and Mac, sshfs is part of the FUSE system, which is able to do many more things than just sshfs, so you need to install both FUSE and sshfs. Most Linux distributions already include FUSE and often sshfs as well. If not, you can use your package manager to install it. (UBuntu and Debian users can just use apt-get install sshfs, which will install FUSE as well.

MacOS users can get a working setup from the OSX FUSE site.

On either OS, you'll need an empty directory to mount onto. It's often useful to give that directory the same name as on the remote side (though that's not required). If you're using a GUI, you can create an empty directory in a convenient place. Or from the command line, you can use mkdir:

mkdir ~/courses/cs105
(Assuming that you already have ~/courses.)

Windows

Windows folks have a bit of a problem. You can search "windows sshfs" and discover that there is a github project, but I don't know whether it actually works, nor which versions of Windows it works on. So you're pretty muchon your own.

Usage

One minor downside of sshfs is that it depends on your network connection being alive. In particular, that means that if you close your laptop you'll probably have to unmount and remount the remote file system. See below for details.

Linux and Mac OS X

To mount the remote filesystem, you use the sshfs command from a terminal window (on Mac OS X, launch the Terminal application; you can find it using Spotlight). In my examples, I'm going to mount a remote filesystem named ~/courses/cs105 onto a local directory named ~/classes/homework. I'm using different names deliberately so that you can see which name goes where; I recommend that you use the same names locally and remotely. You'll want to substitute your own names in the command below, and of course replace "geoff" with your own username. I've put the "need to replace" stuff in italics.

Getting going is dirt-simple: simply type:

sshfs geoff@wilkes.cs.hmc.edu:courses/cs105 ~/classes/homework

in a terminal window. (Notice that I've omitted the tilde in the remote pathname.) Once you get a command prompt back, the remote file should magically appear in your classes/homework folder!

When you're done working, you will want to "unmount" the filesystem. On Linux, this is done with fusermount:

fusermount -u ~/classes/homework

On a Mac, it's done with umount (short for "unmount"):

umount ~/classes/homework

You can also do this if things break. If something goes wrong, unmount and then rerun sshfs. In particular, if your system ever hangs when you try to access a file, or if you get the message "transport endpoint not connected", the cure is to unmount and remount.