How to mount a remote ssh filesystem using sshfs October 28, 2005

Posted by Carthik in ubuntu

SSH is protocol to transfer files securely. Like FTP, but more secure. Many hosting services offer their client the ability to remotely login to their hosting account using ssh. Transferring files to an from an ssh account can be done using the scp command. However, it would be neat if you could mount a remote folder that you can access using ssh on your local computer, so that you can access files on an ssh account just like they were local files on your pc, right? Well now you can! Mount a folder in an ssh account, edit the files locally and save the files, and the file on the ssh server changes too! Isn’t it awesome!!!

We will use sshfs to acheive our goal. The following guide will step you through the process of mouting file systems over ssh on Ubuntu 5.10 Breezy systems.

sshfs: sshfs is a filesystem client based on the SSH File Transfer Protocol. Since most SSH servers already support this protocol it is very easy to set up: i.e. on the server side there’s nothing to do. On the client side mounting the filesystem is as easy as logging into the server with ssh.

Install sshfs by doing a:

$sudo apt-get install sshfs

This will also install fuse-utils and libfuse2, which are required.

Now, let us create a local directory where you want the files mounted. You should create the directory and make yourseld the owner of the directory:

$sudo mkdir /media/dir-name

$sudo chown your-username /media/dir-name

Where “dir-name” is the name of the directory on your local computer where you want to access the files from the remote computer. Say I want the files on the server to be available at /media/home-pc. I want this because the “server” in this case is the desktop I have at home, which allows me to access it through ssh. Let us use “home-pc” as an example for this guide. “your-username” is your username on the local computer.

Go to System->Administration->Users and Groups, select the group “fuse” and then add yourself to this group.



If you prefer to do it the easy way, on the commandline, then use

$sudo adduser your-username fuse

I don’t want to provide a terminal command for adding yourself to a group since there doesn’t seem to be an easy way to add yourself or any user to a group. The only command I know of is the usermod -G command and for this command, you need to list all the groups the user should belong too, even the ones that he/she is already a member of! Anyone know any better on how to add a user to a new group, without having to know what groups he/she is already a member of?

Thanks Shot.

For security reasons, the /usr/bin/fusermount binary is installed in such a way that users cannot execute it. You will have to log out and log in again, to add yourself to the group “fuse”.

Once you have done the above, you can use sshfs to mount the directory you need on the remote host to your local system!

For example, say I want to mount the “/stuff” directory on my home-run server, which has the domain name “example.com”. I would do it by executing the following command:

$sshfs example.com:/stuff /media/home-pc

Where “/stuff” is the folder on the computer with the domain name “example.com”, which I want to mount and access on my local computer at the location /media/home-pc. Remember that the /media/home-pc directory must exist and be owned by you, the user. I already mentioned how to do this in the initial part of this guide.

If you get the following error:

fusermount: fuse device not found, try ‘modprobe fuse’ first

You will have to load the fuse module by doing:

$sudo modprobe fuse

You can add fuse to the modules that are loaded on startup by editing the file /etc/modules and adding a line with only the word “fuse” in it, at the end.

and then issue the sshfs command above again.

To unmount the directory once your work is done, use the command:

$fusermount -u

for example, in my case, I would use

$fusermount -u /media/home-pc

Hat tip: Jorge

More Info: SSH filesystem