I'm sitting here, upstairs, typing on my laptop. There's a file I want on my office machine downstairs. So I should go downstairs and look for the file, right?
Wrong. The TV up here is on NFL Red Zone ( (sigh) Red Zone). I'm addicted, OK? It's hard enough to break away for a bathroom trip.
Several options exist, of course. I could ssh to the downstairs machine, search for the file, and use scp to copy it upstairs. But the file is a picture, and I while I remember what it looks like, I don't remember what name I used for it. So ideally I'd like to use an image viewer, say gthumb or F-Spot to look through the directory and find the file. But I can't, because this computer doesn't mount the downstairs computer's disk.
Ah, but it can. The classic way to do this is to use the Network File System protocol, aka NFS. But that requires work to set up. Besides, some days I might want to search my computer from work, or from a hotel. It's tricky to get NFS to work that way.
Fear not, there is a solution. It uses File System in Userspace (FUSE), a complicated name for using ssh and scp to fool my laptop into thinking that the downstairs computer's files are on the laptop's local drive.
In Ubuntu the way to do this is to install a package called sshfs. Then you just follow the directions on the linked page. Let's say I want to be able to access all the files in /home/rcjhawk on hal, my downstairs computer, from my laptop, majel:
- First make sure I have both hal and majel set up to use ssh communications. If I'm away from home, I'll also need to know hal's ip address, and make sure I can ssh to hal from outside my router.
- Next, install sshfs on majel. Just use
$ sudo apt-get install sshfs
from a terminal window on majel. This doesn't need to be done on hal. Hal's just going to see a series of ssh requests.
Add myself to the FUSE group on majel:
$ sudo gpasswd -a $USER fuse
from the same command window.
- Log off my account on majel, log back on. Yes, it's annoying, but you're not officially added to the FUSE group until you do.
Make a directory on majel. Doesn't matter what the name is:
$ mkdir ~/hal
Now we're going to mount all of hal's directory tree starting from /home/rcjhawk in majel's ~/hal directory:
$ sshfs -o idmap=user rcjhawk@hal:/home/rcjhawk ~/hal
If this works, then running the command
$ ls ~/hal
from a terminal window on majel lists hal's directory tree.
To unmount hal, just run:
$ fusermount -u ~/hal
To make things easier on myself, I created two files. The first, mthal, contains the mounting command, and the second, umthal, the unmount command. Make these executable, put them in your path, and it's easy to mount and unmount.
A caveat: I was getting an error
remote host has disconnected. That occurred because my .cshrc file, which used a variable that's undefined when you are running ssh commands. You can find out how to diagnose that here.
Does it work? We'll, I started typing this on the laptop, and finished it up on the big machine downstairs. So, yes, it does work.
There are also versions of FUSE for BSD, OpenSolaris, and Mac OS X. In fact, I first learned about this trick using my Mac at work. With FUSE you can mount just about anything anywhere. There's even GmailFS, which transforms your Gmail account into backup storage.