NOTE: A long time ago I used to blog for The Open Source Weblog, part of the Weblogs Inc. network, which was eventually bought by AOL. Recently I was looking up an old post I wrote, & I discovered that AOL let all my posts disappear. The only way to access them now is through The Internet Archive’s Wayback Machine. In the interest of preserving history, I’m republishing some of those posts here. Some I’ll edit, & some I’ll present in their original forms, untouched by time.

This post has been edited from the original published November 3, 2005, in order to bring it up to date.

Most Linux users know that you can mount Samba-shared drives using smbfs. In other words, you enable Samba on a machine, share a directory, and then go to another machine & mount that shared directory via smbfs, which makes it appear as though that remote directory is actually directly connected to your machine. Pretty freaking cool, except that (a) you have to have Samba set up, which can be a PITA1, and (b) you can’t share drives over the Net. But don’t despair—now there’s a better way.

Using SSHFS, if you can ssh into machine BAR from machine FOO, you can mount a directory that’s located on BAR and then access it on FOO, as though it was directly connected to FOO. It’s super easy to do it—much easier than with Samba—and better still, everything is encrypted! To add icing on the cake, you can set things up in fstab to make the whole process more automated, if you so desire. Sweet!

Here’s how to do it on Debian.

Install sshfs

Debian makes it easy to install:

# apt-get install sshfs

You may be told that some extra packages will be installed—fuse-utils & libfuse2—which is fine.

Permissions

Once the packages are installed, change your permissions so you can mount as a normal user:

# chmod +x /usr/bin/fusermount

If you don’t want to do that, you could instead add yourself (or any other user) to the fuse group.

# adduser <username> fuse

Mount points

Make a mount point directory on your machine that will point to the directory you’re mounting on the other machine; in my case, I’m mounting a directory named music found on my machine named chaucer:

$ mkdir ~/music_on_chaucer

Load FUSE

Load the fuse module that enables sshfs to work:

# modprobe fuse

Automatically load at boot

You shouldn’t have to do this step again again if you run this command, which adds the module so that it automatically loads at boot:

# echo fuse >> /etc/modules

Mount

Finally, mount the music directory on chaucer to the mount point on your machine; this assumes, of course, that I can SSH into chaucer!

$ sshfs 192.168.0.10:/media/sdc1 ~/music_on_chaucer

You can now start listening to the music in ~/music_on_chaucer.

A word about this command. The syntax is:

$ sshfs [IP|DNS of remote machine]:remote_path local_mount_point

In my case, I used the IP address; if you have the proper entry in your /etc/hosts file, or you’re doing this over the Net to a machine that’s in DNS, use an easy-to-remember name instead of an IP address.

If you don’t put anything after the colon, you will end up mounting your home directory, which may be fine; if you want to mount a specific directory (like I did in my example), put the path after the colon.

Unmount

To unmount, use this:

$ fusermount -u ~/music_on_chaucer

OR this:

$ umount ~/music_on_chaucer

And them’s the basics to sshfs! That is pretty freakin’ easy.

So, to summarize, once you have everything set up, to mount, use sshfs 192.168.0.10:/media/sdc1 music_on_chaucer, and to unmount, use fusermount -u ~/music_on_chaucer or umount ~/music_on_chaucer. What a great tool!

  1. Pain in the ass.