SSHFS: Super Easy File Access over SSH

Who needs NFS or Samba when you can mount filesystems with SSHFS?
Building SSHFS from Source

If your particular Linux distribution does not prepackage SSHFS, or if you simply want to build it from source, this also is pretty easy. First, confirm that you have installed whatever files or packages are required for kernel module development. You need these to build the FUSE kernel module. Then, download the latest source tarballs for both FUSE and SSHFS from SourceForge (see the on-line Resources). Place the downloaded tarball files in a temporary directory, then build and install using the following commands in that directory:

$ tar -xzf fuse-2.5.2.tar.gz
$ cd fuse-2.5.2
$ ./configure --prefix=/usr
$ make
$ su  -c "make install"
$ cd ..
$ tar -xzf sshfs-fuse-1.5.tar.gz
$ cd sshfs-fuse-1.5
$ ./configure --prefix=/usr
$ make
$ su  -c "make install"

After everything is installed, you are ready to perform any of the examples presented previously. After installation, the sshfs and fusermount commands are installed in /usr/bin.

Conclusion

SSHFS and FUSE allow any remote storage to be mounted and used just like any other filesystem. If you can log in with SSH, you have all the access you need.

As I said earlier, FUSE is a framework for creating user-space filesystems. SSHFS is only the tip of the iceberg. There are FUSE-based filesystems to encrypt your files (EncFS) transparently, browse Bluetooth devices (BTFS) or mount a CVS repository as a filesystem (CvsFS). Perhaps you were wondering what to do with all that free space in your Gmail account? Well, GmailFS allows you to mount your Gmail account and use it like a local filesystem. See the FUSE Web site for these and more great projects, or perhaps you would like to write your own. FUSE has language bindings for Perl, Python, TCL, C, C#, Ruby and others.

Resources for this article: /article/8943.

Matthew E. Hoskins is a Senior UNIX System Administrator for The New Jersey Institute of Technology where he maintains many of the corporate administrative systems. He enjoys trying to get wildly different systems and software working together, usually with a thin layer of Perl (locally known as “MattGlue”). When not hacking systems, he often can be found hacking in the kitchen. Matt is a member of the Society of Professional Journalists. He is eager to hear your feedback and can be reached at matt@njit.edu.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

SSHFS and Apache

Anonymous's picture

What about using sshfs to mount /var/www from a remote filesystem?

I keep getting a very generic 'Permission Denied' error when trying to chown /var/www (even as root) and under Apache I receive a 403 Forbidden error - again, very generic.

WARNING

Anonymous's picture

This is not secure!!!!

SSH keys with empty passphrases are useless - in fact they are worse than useless, they are a liability. You might as well store your passwords to the remote system in plain text in a file called "README_all_passwords.txt"

mount fatfs using fusermount command

Anonymous's picture

dear all,
how can i mount a fat fs using fusermount.. which uses a fusefat ....
thanks in advance,
jomel

one caveat

Anonymous's picture

This is great for users without root access on the storage server. But operations will be performed as the logged in user. I'm guessing that if you logged in as root, it might support automatically chown'ing.. but a) that requires trusted root login (which opens up security issues that even NFS doesn't) and b) uid mapping may become an issue like it is with any network storage.

The only thing better is sshfs+autofs

Thomas Jansson's picture

Instead of having gnome mount the sshfs share upon startup one can use autofs instead. This is even easier. When ever I whish to acces a remote filesystem I just enter the the path /mnt/sshfs/foobar.com and then the autofs daemon mounts the remote filesystem for me.

I've written a small article on how to setup autofs and sshfs on my blog: http://www.tjansson.dk/?p=84 called "Autofs and sshfs - the perfect couple" if anybody is interested. :)

Password without security weakness

Super Mike's picture

Instead of an empty passphrase, is there an smbpasswd-like way where I can generate the user/pass combo in an encrypted file and use that?

Or, what if I edited the C code with a hard-coded user/pass combo and compiled with that?

Great Think

WarDragon's picture

Yes, unlike nfs, this is what we want, easy to use and secure. Great

Thank you!

Shannon Coen's picture

This was just the solution I was looking for!

Very curious about FUSE now (GmailFS? cool!).

Thanks again,
Shannon Coen

sshfs article

meltedmossy's picture

I don't know if anyone else had this problem, but to get it to work I had to do a chmod root:fuse on /dev/fuse.

Before I did that, logged in as tim(me) it gave me an denied error..had to use sudo and then it didn't work as only root was able to see the directory and use it properly. Kind of pointless if someone doesn't have sudo access!

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix