UPDATE: LUFS AND SHFS are deprecated in favor of SSHFS. I still left the description below
Suppose that you want to mount a filesystem on a remote computer sitting somewhere on the internet. There are two standard ways to do this in Linux:
NFS (Network FileSystem) - the standard UN*X way
Samba (SMB/CIFS/Microsoft Windows Networking) - can be handy.
Samba is a good Linux tool for setting up Microsoft
networking
NFS is nice: it's fast, it's standard, etc. Unfortunately, there
are drawbacks to NFS, at least as far as I can tell:
1) You will need FULL access to both systems in order to configure them
to use NFS - this means that you will need to be root on both systems
2) Both systems need to be able to talk to each other directly without
being impeded by firewalls, gateways, etc. This isn't going to work in
my case (and probably in yours) where my computer is not directly
on the internet, but instead is behind a router and firewall. Nevertheless,
there ARE machines on the internet with filesystems that I really want to
mount (not really, but in principle).
3) I have experienced machine crashing when one side of the link goes
down. In other words, if one machine is expecting the other machine to be
there, and it isn't... BOOM... good luck regaining control. Note that
this happens to me whether I use so-called "hard" or "soft" mount
options.
4) Neither NFS nor Samba is particulary secure. I would never dare
set up a share without being behind a firewall. Even then
I'm a bit scared.
The Alternatives: SSHFS LUFS and SHFS
There ARE alternatives to NFS and Samba, and I will document two of
them here - namely
lufs and
shfs.
UPDATE: added SSHFS.
The beauty is
that they use your favorite secure networking tool - ssh! Everybody
loves ssh... it's great. Personally I find that SHFS
SSHFS is more usable now the only choice.
First, a brief comment is in order. Since you will be using ssh, you might want to use ssh authentication. This will allow you to login to a remote computer without having to type your password every time. I use it, and I'm quite happy with it (especially since it is still secure).
Obviously you will need to be the root user (but only on the local machine) to do ALL of the following.
Both LUFS and SHFS and SSHFS are kernel modules (in addition LUFS utilizes a "user space" daemon), so you will need to download the module source and compile it. Before you can do that, however, you will need to make sure that your "kernel headers" are installed (if you compiled your own custom kernel then don't worry about it).
If you are running a stock Debian kernel then use "apt-get" to install your relevant kernel headers package. The following command will do this for you:
apt-get install linux-headers-`uname -r`Note that ` is a backtick, not a single quote '.
The *BETTER* way to do this is to just compile your own custom kernel from source - then you won't need these silly headers if you keep your source directory around.
If you are using Debian, then you will also want to install the package
module-assistantThis package will automatically compile and install your modules for you.
SSHFS (Replacement for LUFS and SHFS)
Now it's time to get a hold of the SSHFS utilities and the FUSE kernel
module (which you will have to compile).
In Debian just apt-get the packages:
sshfs fuse-utils fuse-source
The remainder of this document will assume that you are using Debian. Now you will need to compile and install the FUSE module. This can be achieved by issuing the following two commands
module-assistant build fuse module-assistant install fuseNow you MAY need install the fuse module with the command
modprobe fuseThis is sometimes done automatically by the package. TIP: check the newly-created device /dev/fuse. It should be owned by user:group= root:fuse. If it is not then you will need to fix that!!! Be careful that your settings will persist after reboot.
Now add the privileged users to the group "fuse" (just edit the file /etc/group and add your username). You probably need to log out and log back in for the settings to take effect.
That's IT!!! For example, to mount the directory "/remote/directory" which is located on the (remote) computer remotecomputer.com, I would issue the command
sshfs username@remotecomputer.com:/remote/directory /local/directoryTo unmount use the command
fusermount -u /local/directory
TIP: Note that using the "home" directory designation "~/" in place of "/remote/directory" does not seem to work. Instead you will probably be forced to use the full path for remote directories.
LUFS (Linux Userspace FileSystem)
DEPRECATED... USE SSHFS INSTEAD
Now it's time to get a hold of the LUFS utilities and the LUFS kernel
module (which you will have to compile). You can either
go to the
original website, or (if you are
using Debian) then you can just apt-get the packages:
lufs-source lufs-utils
There used to be an "lufs-crytofs" package - I don't know if encryption has been included into the other packages. That might be kind of cool to look at.
The remainder of this document will assume that you are using Debian. Now you will need to compile and install the LUFS module. This can be achieved by issuing the following two commands
module-assistant build lufs module-assistant install lufs
That's IT!!! It should work right out of the box now! So, for example, to mount the directory "/remote/directory" which is located on the (remote) computer remotecomputer.com, I would issue the command
lufsmount sshfs://username@remotecomputer.com/remote/directory /local/directory
Note that using the "home" directory designation "~/" in place of "/remote/directory" does not seem to work. Instead you will probably be forced to use the full path for remote directories.
At this point you might want to allow users (other than root) to be able to use the "lufsmount" and "lufsumount" utilities. You will need to change the "suid" flag on the binaries "/usr/bin/lufsmount" and "/usr/bin/lufsumount" by issuing the following commands (as root)
chmod +s /usr/bin/lufsmount chmod +s /usr/bin/lufsumount
SHFS
DEPRECATED... USE SSHFS INSTEAD
This is
another project
which implements the same thing, with a few
differences. First, it runs only as a kernel module (whereas
LUFS actually runs as a kernel module AND in "user space").
This means that SHFS is likely faster than LUFS, but LUFS is more flexible.
The installation will be almost identical. First you will need to apt-get the Debian packages
shfs-source shfs-utils
When you get these packages, you will be prompted to "suid" the shfs utils so that ANY user will be able to mount and unmount. Note that for LUFS above you needed to do this manually. Apparently the SHFS package maintainers already thought this through, which is kind of nice. I obviously said "yes" since I trust all of my users (I'm lucky).
Now I just have to build and install the module by issuing the following commands (in Debian)
module-assistant build shfs module-assistant install shfs
That's IT! Now to mount the remote directory I just type
shfsmount username@remotecomputer.com /local/directory
Clearly this mounts username's home directory (on the remote machine) onto /local/directory (on the local machine). I can actually specify any remote directory that I want by using the command
shfsmount username@remotecomputer.com:/remote/directory /local/directory
In some sense, I feel that SHFS is better if you just want to use SSH for a standard filesystem mount. It's simpler (although not much, I admit). LUFS, however, seems far more flexible and has a lot of fun toys (which I will need to check out in the future... like encrypted filesystems).
This page has been visited times since April 8, 2005