Cloud

Use Fuse to mount remote ssh directories

Vincent Danen introduces the Fuse Project, a way to edit files remotely with plugins like sshfs, which transparently makes an SFTP connection to a remote system seem like nothing more than a local file directory.

Traditional methods for uploading, downloading, or editing remote files predominantly have consisted of using an FTP client. An FTP client works fine for uploading and downloading, but editing remote files is a chore, as you have to download a file, edit it, then upload it again. And privacy with FTP is an issue as well.

More recently, other methods have become available, such as FTP with TLS support to protect authentication credentials, and the use of SFTP and SCP to copy files with encryption. While these solved the privacy issues, the convenience factor remained absent; you still needed to download a file, edit it, then re-upload it.

Using protocols like DAV allowed for the use of sharing files via HTTP or HTTPS, and some FTP clients made editing remote files more transparent — removing the manual steps. Even then, navigating remote file systems was limited to the interface of the FTP or DAV client.

The FUSE project has made editing remote files convenient by allowing local-filesystem-like access to remote files. With plugins like sshfs, which transparently makes an SFTP connection to a remote system seem like nothing more than a local directory, convenience and privacy are both available.

Most Linux distributions today provide FUSE support and also provide the sshfs plugin, so it should be a simple matter to install. Some distributions limit access to FUSE, which can be a wise thing considering how powerful it is. Distributions like Mandriva require that users who are allowed to use FUSE are added to the fuse group, which can be accomplished by executing, as root:

# usermod -G fuse joe

This will add the user joe to the fuse group, granting him permission to use FUSE. When this is done, mounting a remote directory that you normally have access to via ssh or SFTP is a simple matter of executing, as the user:

$ sshfs host:/path ~/localpath

This mounts the directory /path on the remote host host in the directory ~/localpath on the local system. Executing the mount command now, it is plain that the remote directory is mounted:

$ mount
host:/path on /home/joe/localpath type fuse.sshfs (rw,nosuid,nodev,max_read=65536,user=joe)

Navigating to ~/localpath will enter the remote file system, and from here you can use any local tool to manipulate files as you wish. You can copy files using cp, navigate the directory tree using Konqueror, and edit files with vim or OpenOffice.org, etc.

To unmount this directory, use the fusermount command:

$ fusermount -u ~/localpath

The sshfs command can also take a number of extra arguments, such as the -p argument to connect to a port other than the standard port 22. Adding sshfs to /etc/fstab can also allow for persistent remote directory sharing using FUSE and sshfs, instead of other connection methods such as NFS. By default, the FUSE mounts are unique to a single calling user, but with options such as -o allow_root or -o allow_other, you can permit access to the mounts to root and/or other users respectively.

FUSE is a very powerful system, and sshfs is just one plugin that can be used with it. FUSE modules exist to provide read/write access to NTFS partitions, navigating archive files without expanding them first, navigating relational databases as if they were regular file systems, encrypted file systems, and more. More information on FUSE and the various plugins available for it can be found at http://fuse.sourceforge.net/.

Get the PDF version of this tip here.

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

About

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

Editor's Picks