The ability to export remote file systems is extremely useful,
which is why programs like NFS and Samba are so popular. Unfortunately, both
are typically tied to a local network which limits their usage somewhat. An ideal
file system would allow for encrypted connections to a remote site, without
resulting in complicated VPN connections.

This is exactly what shfs,
the SHell File System, does. It allows for the mounting of remote directories
via ssh by using a kernel module
(like smbfs) and a user-space tool,
like mount. To get started, you can download shfs from http://shfs.sourceforge.net/;
the latest version as of this writing is 0.35. Before starting, be sure you have
the kernel source for your currently running kernel available and be sure the C
compiler you have is the exact version that was used to compile the kernel.

$ mv shfs-0.35.tar.gz /usr/local/src
$ cd /usr/local/src
$ tar xvzf shfs-0.35.tar.gz
$ cd shfs-0.35
$ make
$ sudo make install

The example above will compile the kernel module for your
kernel (shfs supports both the 2.4
and 2.6 kernels) and will also compile the shfsmount
utility.

If you are using gcc4,
you will need to download and apply this patch to the shfs source for it to compile properly:

http://atrey.karlin.mff.cuni.cz/~qiq/src/shfs/shfs-0.35/gcc4-compilefix.patch.

Once you have shfs
installed, load the kernel module and mount your first remote file system:

# modprobe shfs
# shfsmount user@remote /mnt/user

This will mount the home directory of user@remote in the
directory /mnt/user. You can also use
mount itself:

# mount -t shfs user@remote:/data /data

This would allow you to automount certain directories at boot
by adding entries to /etc/fstab. Of
course, you would want to use ssh keys with that because on every mount, you’ll
be asked for a passphrase or password.

As you can see, shfs
is extremely easy to use and versatile. It allows you to mount a remote drive
at the office that your desktop at home recognizes as a local file system, but without
the hassles of making anything more than ssh available on the remote system.

Delivered each Tuesday, TechRepublic’s free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!