sshfs

I love sshfs.

Why?

Reasons for loving sshfs

Because it makes it easy to extend the computational power of the computer I am running programs on to files all over the net (well at least files on computers all over the net where I have login accounts, but that's all I want).

I am currently working on one computer, and I realize that I would like to move some (music) files from one computer at home to a computer of a friend (who has higher bandwidth than my home). I do have ssh-accounts on both computers, and they are powered on. So I just mount these two computers with sshfs, switch to my locally running mc, choose what directories to copy and press F5. Copying from a remote source to a remote target is not possible with scp.

Another example of sshfs' usefulness is this. I administer a web-application on a server at work. Rather than login to that server and using local programs to edit files, I use sshfs from my computer and edit the files with the applications I have running locally. This way I can use all the extensions/customizations that I have choosen over the years. To get that while working with applications running on the server, I would have had to manage installation/administration of many programs (Emacs, with a number of plugins/extensions, libraries for the X Window System (even if the X server is of course remote, since the server is headless) including monitoring the outcome of security updates to them) and keeping the customizations in sync with my own computer.

This is in addition to the two other applications of sshfs that I have already written about: wget and p2p-backup.

I enjoy two properties of SSFS compared to NFS:

  1. Does not require root access to the server and static configuration of the shares
  2. Works securely accross networks using only a standard port (22) for TCP-traffic.

Problems with sshfs

On systems that are frequently powered down SSHFS is not as convenient as NFS, since NFS shares that are mounted at suspend time will be available again whenever the network is back after resume. For sshfs mounted shares, you need to hack your own resume/remount mechanism. Such a mechanism should be able to do this:

  1. At suspend time, record
  2. At resume time, for each user try to remount the shares that this user had mounted before suspend

Below there is an implementation in BASH of such a mechanism.

Recording current shares

mount | grep sshfs# | mawk {'print $1 " " $3'} > .sshfs-shares-record
mount | grep sshfs# | cut -d "," -f 5 | cut -d "=" -f 2 | cut -d ")" -f 1 > .sshfs-users-record
paste -d " " .sshfs-shares-record .sshfs-users-record > /var/run/sshfs-record

Remounting them after resume

while read line ; do
    server=`echo $line | mawk '{print $1}' | cut -d "#" -f 2 `;
    mountpoint=`echo $line | mawk '{print $2}' | cut -d "#" -f 2 `;
    user=`echo $line | mawk '{print $3}' `;
    echo "su $user sshfs $server $mountpoint;"
done < <(cat /var/run/sshfs-record)

sshfs share persistent over reboot

The scripts above should work just as well over a reboot cycle as over a suspend-resume cycle. Join these scripts to one and let "start" issue the remounting part and "stop" the recording bart. Put this in /etc/init.d/ and use update-rc.d.

comments powered by Disqus


Back to the index

Blog roll

R-bloggers, Debian Weekly
Valid XHTML 1.0 Strict [Valid RSS] Valid CSS! Emacs Muse Last modified: 2007-12-12