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.
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!
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 folks have a bit of a problem. You can search "windows sshfs"
and discover that there is a program from
Googlecode.com, but the site says it's not being developed any
more. And it only runs on Windows 2003, Vista, 2008, 2008R2, and 7.
But if you're running Windows 8, all is not lost; see below.
On the Googlecode site, you'll find a download link in the navigation
bar on the left. Download setup.exe
to your desktop. If
you're running Windows 8, before you run it you need to
right-click it, select "Properties", and then choose the
"Compatibility" tab. You'll find a checkbox that allows you to run
the program in Windows 7 compatibility mode. Check it, and close the
properties window.
Now double-click on setup.exe
to run it. You can ignore
the warning about Dokan; the installer will take care of it. (Like
all Windows programs, it will force you to reboot as part of the
process.) Eventually you'll wind up with an application called "Sshfs
Manager" installed.
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.
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.
Note: These instructions are adapted from a site at DigitalOcean.com. I tested them on Windows 8, but not extensively. Please let me know if you encounter problems.
On Windows, the Win-SSHFS
program offers a graphical
interface. Launch it, and then:
Add
button in the lower-left corner of
the window
knuth.cs.hmc.edu
courses/cs105
(note that you
should specify it relative to your home directory,
i.e. without a leading tilde or slash)
E:
") for Windows to use
E:
), and
you can use all your familiar programs to access them. When you are
done, click the "Unmount" button in the Sshfs Manager.
I'm told that
by default, Win-SSHFS
will run every time you boot your
computer, and that you can change the default by going to the Taskbar,
right-clicking on the application icon, and un-checking "Run at
startup."