mount_sshfs

Mount Remote SSH Filesystem with FUSE

Mounting a remote filesystem with sshfs allows you to do anything on the files, just like local files. Because it is an SSH connection, it is secure (encrypted, two-way authenticated), and it works with almost any ssh server.

Mounting with FUSE sshfs mount filesystems on the filesystem level, so unlike Gnome VFS (Places: Connect to Server), all programs can work with the files. FUSE sshfs also works without a graphical user interface.

Procedure described in this article has been tested with Ubuntu 5.10 Breezy Badger. The procedure is likely different on Fedora Core.

© 2005-2007 Tero Karvinen


Requirements

  • SSH account. You have it if you can log into it with a command like ‘ssh karvinen@example.com’.
  • Ubuntu 5.10 Breezy Badger or later. These instructions don’t work with older Ubuntu 5.04 Hoary Hedgehog, but they work with eg. 6.06.
  • Root account on the client machine (to install sshfs and fuse, to load the kernel module, to mount).

No special priviledges are needed on ssh server.


Install SSHFS

Add universe and multiverse repositories to /etc/apt/sources.list.

Install sshfs, required programs (fuse-utils libfuse2 and maybe fuse-module) are installed automatically:

$ sudo apt-get install sshfs


Load FUSE kernel module

This should have happened automatically, but it has not (Bug 1680). To work around it

$ sudo modprobe fuse

If you want it to work after reboot, add it to /etc/modules.

Error message that indicates that you forgot to load the module: “fusermount: fuse device not found, try ‘modprobe fuse’ first”


Mount SSH Filesystem

In this example, we mount home directory of user “karvinen” on server “example.com”. Root access is required for mounting. User mounting tool fusermount does not seem to work on Ubuntu 5.10 at the moment (2005-11-23) (Partially described on [[https://launchpad.net/distros/ubuntu/+source/gmailfs/+bug/352|bug 352).


Create mountpoint

$ cd $HOME
$ mkdir sshfs
$ chmod og-rwx sshfs/
$ mkdir sshfs/tkarvine-example

$HOME is normal users home directory, for example “/home/tero/”. The extra directory “sshfs/” prevents other users from reading any sshfs mounted file contents. For actual mountpoints, “user-host” is a good naming convention. Here I used tkarvine-example for account ssh://tkarvine@example.com.


Mount Remote Filesystem

$ sudo sshfs karte@myy.helia.fi: sshfs/karte-myy/ -o allow_other
karte@myy.helia.fi's password:
$ ls sshfs/karte-myy/ |head -2
 bin
 iki-fi-karvinen-backup

If you saw the contents of your remote home directory with ls, well done, you have mounted an ssh filesystem remotely.


Notes

The procedure above works. However, it would be practical if users could mount directories and I got this working later, after writing the procedure above.

It is also possible to mount as a user. In the following, root allows user “tero” to mount fuse filesystems.

$ sudo gpasswd -a tero fuse
$ mkdir testmount/
$ sshfs tkarvine@example.com: testmount/
$ ls -1 testmount
foo
bar
$ fusermount -u testmount/


Troubleshooting


Couldn’t find package sshfs

‘sudo apt-get install’ says “E: Couldn’t find package sshfs”. Enable universe and multiverse in /etc/apt/sources or use the GUI tool System: Administration: Update Manager to add them.


fuse: failed to exec fusermount: Permission denied

You are not member of “fuse” group.

Add yourself to fuse group:

$ sudo gpasswd -a $LOGNAME fuse
Adding user tero to group fuse

Log out and back so that shell knows about your new groups. Optionally check that “fuse” is mentioned in the list printed by ‘groups’. If ‘sshfs server: mountpoint’ does not give the same error message, group problem is solved.


Fuse device not found

“fusermount: fuse device not found, try ‘modprobe fuse’ first”. Also many other, more obscure error messages if you try to use FUSE without loading the module. Not loading the module automatically is a bug.

$ sudo modprobe fuse


fusermount: old style mounting not supported

‘$ fusermount tkarvine@example.com: tkarvine-example/’ “fusermount: old style mounting not supported”. Use ‘sudo sshfs’ as described above. ‘fusermount’ and ‘mount -t sshfs’ don’t seem to work at the moment.


mount: unknown filesystem type ‘sshfs’

‘$ sudo mount -t sshfs foo bar’ “mount: unknown filesystem type ‘sshfs’“. Use ‘sudo sshfs’ as described above. ‘fusermount’ and ‘mount -t sshfs’ don’t seem to work at the moment.


No write permisson, files owned by unkown user

By default, files are owned by uid and gid on remote server. Most likely they are different in two systems. ‘ls -l’ shows weird user and group as file owner. They are either wrong names or just numbers.

Umount your sshfs mounted directory if needed

$ sudo umount tkarvine-example

Find out your numeric user id

$ id
uid=1000(tero) gid=1000(tero)

Specify local user and group id.

$ sshfs tkarvine@example.com: tkarvine-example/ -o idmap=user -o uid=1000 -o gid=1000

Now file owners are correct

$ ls -l tkarvine-example/
drwxr-xr-x 1 tee tee      4096 2007-04-13 12:28 world-domination
-rw-r--r-- 1 tee tee      8994 2006-09-12 15:21 How to get rich by drinkign tea.txt
...

Saving works now.

See also “-o allow_other”.


Links

FUSE, Filesystem in Userspace http://fuse.sourceforge.net/

SSHFS, SSH Filesystem http://fuse.sourceforge.net/sshfs.html

[Fuse sshfs performance] and reliability already seem far far better than the built in GNOME way. [..] [Fuse is] already in Ubuntu (don’t forget to add yourself to the fuse group, oh, and read the manpage). http://www.whiprush.org/2005/10/fuse.html

fusermount requires the fuse kernel module to be loaded, which they can’t do. https://launchpad.net/distros/ubuntu/+source/fuse/+bug/1860

Storing files off-site with gmail http://www.debian-administration.org/articles/198

Please check and see if gmailfs version 0.4-1ubuntu1 solves your issue. https://launchpad.net/distros/ubuntu/+source/gmailfs/+bug/352

[bug report has been submitted] http://ubuntuforums.org/showthread.php?t=24386

http://ubuntu.wordpress.com/2005/10/28/how-to-mount-a-remote-ssh-filesystem-using-sshfs/

http://ubuntu.wordpress.com/2005/11/08/using-flickrfs-on-ubuntu/

Jones 2006: Mounting a Remote Filesystem with sshfs. “[-o idmap=user -o allow_other -o uid=LOCALUID -o gid=LOCALGROUP] will not only mount the remote share, but will resolve any user id mismatches with the ones you specify with the uid and gid options.” http://www.oreillynet.com/onlamp/blog/2006/11/mounting_a_remote_filesystem_w.html


Conclusions

FUSE sshfs works well enough for advanced users, but is still far from production quality. The ability to install it using apt-get makes sshfs a lot easier to use than it’s predecessor, LUFS (Linux Userland Filesystem). Mounting a filesystem in FUSE is superior to Gnome VFS. In the near future, FUSE will likely work very transparently and many other virtual filesystems become obsolete.



Posted in Old Site | Tagged , , , , , , | Comments Off on mount_sshfs

Comments are closed.