Remotely mounting directories through SSH

I manage a fair number of Linux hosts, and have recently been looking for ways to securely mount remote directories on my servers for administrative purposes. NFS and Samba don’t have a terribly good security track record, so I don’t like to use either of these solutions unless truly warranted. Rsync over SSH is pretty sweet, but it’s not quite as transparent as I would like it to be. Since all of my hosts support SSH, I started to wonder if someone had developed a solution to transparently move files between two systems using SSH. After a bit of digging, I came across the super cool sshfs fuse module, which does just that!

Sshfs allows you to “mount” a remote directory over the SSH protocol, and it provides transparent access to files stored on a remote server. To use this nifty module with Fedora, you first need to install the fuse-sshfs package:

$ yum install fuse-sshfs

Once the fuse kernel modules and userland utilities are installed, the sshfs utility can be used to mount a remote directory on a local mount point. In the following example, the sshfs utility is used to mount the directory $HOME/backup on the server giddieup on the local directory /home/matty/backup:

$ sshfs -C -o reconnect,idmap=user giddieup:backup/ /home/matty/backup

Once the sshfs command completes, you can add and remove files to the locally mounted directory (/home/matty/backup in this case), and these changes will be automatically propogated to the remote server. The first time I ran sshfs I received the error “Operation not permitted.” After digging into this further, I noticed that the fusermount and sshfs utilities were not setuid root out of the box. To address this problem, I changed the group ownership of both utilities to fuse, put myself in the fuse group, added the setuid bit and changed the mode of both executables to 0750. The opensolaris community is currently porting FUSE to Solaris, and I am looking forward to eventually being able to use SSHFS on my Solaris hosts!

4 thoughts on “Remotely mounting directories through SSH”

  1. Great little utility – it’d be even better when ported to Solaris. Thanks for bringing it to light.

  2. NFSv4 would definitely work, but I really don’t want to run RPC and NFS services if I don’t have to. SSHFS is perfect for administrative file access, and works pretty well (at least I haven’t found any issues with it).

  3. Hi Matty, this all looks very interesting to me (a relative newbie) and hence this post … I am trying to use sshfs to mount remote Maildirs securely. mutt works nicely but procmail does not: man procmail tells me that the diagnostics message “Unable to treat as directory” is because “Either the suffix on [the directory] would indicate that it should be an MH or maildir folder, or it was listed as an second folder into which to link, but it already exists and is not a directory”. Maybe I should not expect procmail to be able to operate over sshfs? Dominic

Leave a Reply

Your email address will not be published. Required fields are marked *