Wednesday, July 22, 2009

Mounting remote filesystems via sshfs

If you have access to a remote computer via ssh , it is possible to mount your home directory on the remote machine locally.

Let us assume the following.

You have an account on a remote machine A with IP a.a.a.a and you are working on a local machine B. You want to mount the your home directory on A to a folder on B. I am also assuming that both the machines are running Ubuntu/Debian.

Step 1

On machine A install open-ssh server.

$ sudo apt-get install open-sshserver

Step 2

Ensure that you are able to log in to A from B via ssh

$ ssh fermi@a.a.a.a

This will prompt you with a key finger print of A and ask you whether you want to add this key to the list of trusted machines. Accept the key. Now it will prompt for the password on the remote machine.
Log out from A by typing logout.

Step 3

Install sshfs and fuse-utils on the local machine B.

$ sudo apt-get install fuse-utils sshfs

Step 4
The sshfs package can mount remote directories / filesystems via fuse. (FUSE is file systems in user Space). On ubuntu , you must be a member of fuse group to access FUSE.
You can manually edit /etc/groups to add your user name to fuse group. Or it can be done from System->Administration->Usersand Groups on Gnome desktop ( on ubuntu).

Step 5
Create a directory on the local machine.

$mkdir remote_dir

Now, mount the remote directory.

$ sshfs fermi@a.a.a.a: remote_dir

(There is a colon after the IP address above) . You home directoy on the remote machine A will be visible under remote_dir folder.

You can unmount the remote directory with the following command.

$ fusermount -u remote_dir

6 comments:

aby said...

I assume remote_dir on both local and remote has to be the same. like: /this/directory/same

cause there's no mount point indicated in sshfs line. am I right?

Travis Hines said...

This works great. I used it to mount my storage folder to my kid's computer (I made it read-only). The server was Ubuntu, and the client was Fedora 11.

sshfs user@ip.add.re.ss:/storage storage -o ro

Ajay said...

aby. dir paths and names can be different.

aditya said...

I followed all the steps as written, but sshfs fails with error:

fuse: device not found, try 'modprobe fuse' first

After trying 'modprobe fuse' as root:
FATAL: Module fuse not found.

yum list|grep fuse shows:
fuse.i386 2.7.4-1.el4.rf installed
fuse-devel.i386 2.7.4-1.el4.rf installed
fuse-smb.i386 0.8.7-1.el4.rf installed
fuse-sshfs.i386 2.2-1.el4.rf installed

also: /dev/fuse is present
but trying to access it gives error:
/dev/fuse: No such device

what could be wrong?
I'm using RHEL4-i386 update4

For 'uname -a' output is:
Linux NCDPN0002 2.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17 EDT 2006 i686 i686 i386 GNU/Linux

I'm using 'rpmforge' repos

Please let me know how to get it to work now

thanks

UbuntuGuru said...

@aditya
I am no redhat guru. It seems your fuse module is not loaded. Will you look at the following tutorial specific to RH http://www.cyberciti.biz/tips/rhel-centos-mounting-remote-filesystem-using-sshfs.html

FUSE was officially merged into the mainstream Linux kernel tree in kernel version 2.6.14.
You seem to use an older kernel.

Sven Buschbeck said...

Hi all,

@aditya
Had the same problem. You need to add any user which should be allowed using fuse to be member of the fuse group - fixed the problem for me. :)

usermod -G fuse -a [your login]